FTPlib

Christophe Deleuze

1 What is FTPlib

FTPlib is a C library providing communication facilities implementing the client side of the Internet File Transfer Protocol (FTP). Thus, it allows applications to interact with FTP servers. It is heavily based on the source code of NetKit-ftp [1], a popular FTP client program for Unix machines.

FTPlib is written in C, but bindings for a large subset of the API are also provided for the Objective Caml^{1} language.

2 Library API

Briefly, you have all classic high level FTP commands for connecting, listing, changing, creating, and deleting directories, renaming, deleting, and transfering files.

The library supports “FTP gateways”: if the environment variable FTP_GATEWAY is set, ftp_open will try to open the connection to this host, providing login@server as login.

Low level functions are also provided, that allow to:

• send a raw FTP command and get the server answer string as return value,

• perform stream to file (for put) and file to stream (for get) file transfers (contrary to high level file transfers, that are only file to file), using callback functions.

Have a look at the ftplib.h file for details. An example toy application is provided in example.c.

3 Caml bindings

All high level C functions are mapped to Caml ones, but low level functions are not available (they may be in the future, if I figure out how to copy arbitrary blocks of bytes from C to Caml).

Have a look at the ftp.ml file for details.

1http://caml.inria.fr http://christophe.deleuze.free.fr/D/ftplib.html  March 1, 2011

4 Installation

$ tar xvzf ftplib.tgz
$ cd ftplib

If you don’t want the caml bindings, uncomment the appropriate line in the Makefile, then make libftp.a. Type make example to compile the toy example.

If you want the caml bindings, make sure the appropriate line is not uncommented in the makefile, and set the appropriate value to the Makefile

CAMLH_DIR variable. Do make libftp.a ftp.cmxa ftp.cma. ftp.cmxa is

a native code caml library, ftp.cma a bytecode caml library. You may want to build only one of these. make ocamlftp builds a Caml toplevel containing FTPlib. You can then use this toplevel as a primitive FTP client!

5 Various notes

This documentation is awfully short and incomplete.

The library is usable but a bit incomplete as well. It hasn’t been tested extensively so far, but I guess NetKit-ftp base code is pretty stable. It is currently used in the wsync^{2} application (A Caml application, that uses only a small subset of the API).

Send bug reports, comments, suggestions, whatever to elviok@free.fr. The File Transfer Protocol specification, a bit confused, is described in [2, 3].

For a synthetic, commented, description of the protocol, see [4].

Other FTP related specifications are [5, 6, 7].

References

[1] David A. Holland. Netkit-ftp. Unix FTP client program. http://www.hcs.

   harvard.edu/~dholland/computers/netkit.html

[2] J. Postel and J. Reynolds. File Transfer Protocol (FTP). RFC 959, IETF,

   October 1985. http://www.ietf.org/rfc/rfc959.txt

[3] R. Braden. Requirements for Internet Hosts – Application and Support. RFC

   1123, IETF, October 1989. http://www.ietf.org/rfc/rfc1123.txt

[4] D. J. Bernstein. FTP: File transfer protocol. web site. http://cr.yp.to/

   ftp.html

[5] M. Horowitz. FTP Security Extensions. RFC 2228, IETF, October 1997.

   http://www.ietf.org/rfc/rfc2228.txt

[6] B. Curtin. Internationalization of the File Transfer Protocol. RFC 2640,

   IETF, July 1999. http://www.ietf.org/rfc/rfc2640.txt

2http://christophe.deleuze.free.fr/D/wsync.html

[7] R. Housley. Encryption using KEA and SKIPJACK. RFC 2773, IETF,

   February 2000. http://www.ietf.org/rfc/rfc2773.txt