ftp-conduit-0.0.1: FTP client package with conduit interface based off http-conduit

Network.FTP.Conduit

Description

This module contains code to use files on a remote FTP server as Sources and Sinks.

This module makes use of the FTP STOR and RETR commands. According to the FTP spec, these commands are set up so that a server response is sent at the beginning and end of the data transfers. The current Conduit library doesn't allow the code that creates the Source / Sink of the data transfer to run checks _after_ the data has been transferred. Because of this fact, this module exposes two interfaces.

One interface is an interface that simply creates a Source / Sink and does not check the server return code after the data transfer (because it can't, as stated above). These two functions (putFTPFile and getFTPFile) return a Sink and a Source, respectively.

Using these functions looks like:

 runErrorT $
   runResourceT $
     (getFTPFile $ fromJust $ parseURI
       "ftp://ftp.kernel.org/pub/README_ABOUT_BZ2_FILES") >>=
         (\ (_, s, _, _) -> s $$ consume)

The other interface is one that does check the error code after the data transfer. In order to do this, however, these functions must actually be the ones that apply the $$ (connect) function, so they can perform the checks afterword. These are the connectDownloadToSink and connectSourceToUpload functions. You pass them a Sink and a Source, respectively, and they will call the $$ (connect) function, check that the data transfer was successful, and then safely tear down the FTP connection.

Using these functions looks like:

 runErrorT $ runResourceT $ connectDownloadToSink
   (fromJust $ parseURI
     "ftp://ftp.kernel.org/pub/README_ABOUT_BZ2_FILES") consume

The functions here operate on the ErrorT monad transformer, because the server can send unexpected replies, which are thrown as errors.

Synopsis

Documentation

data FTPError Source

UnexpectedCode has the form (Expected code, full response string)

putFTPFile :: URI -> ResourceT (ErrorT FTPError IO) (Handle, Sink ByteString (ErrorT FTPError IO) (), ReleaseKey, ReleaseKey)Source

Returns (Handle of the control connection, the Sink itself a destructor for the control connection, and a destructor for the data connection).

The caller should use the handle to check for return codes, and release the ReleaseKeys when appropriate.

getFTPFile :: URI -> ResourceT (ErrorT FTPError IO) (Handle, Source (ErrorT FTPError IO) ByteString, ReleaseKey, ReleaseKey)Source

Returns (Handle of the control connection, the Source itself, a destructor for the control connection, and a destructor for the data connection).

The caller should use the handle to check for return codes, and release the ReleaseKeys when appropriate.

connectDownloadToSink :: URI -> Sink ByteString (ErrorT FTPError IO) b -> ResourceT (ErrorT FTPError IO) bSource

Give this a Sink and it downloads the given URI to it. This function calls $$.

connectSourceToUpload :: URI -> Source (ErrorT FTPError IO) ByteString -> ResourceT (ErrorT FTPError IO) ()Source

Give this a source and it uploads it to the given URI. This function calls $$.