Chapter 60. FTP Client Features

FTP Client API

This package implements an FTP client. The API is in include file install/include/ftpclient.h and it can be used thus:

#include <network.h>
#include <ftpclient.h>
It looks like this:

ftp_get

int ftp_get(char * hostname, 
            char * username, 
            char * passwd, 
            char * filename, 
            char * buf, 
            unsigned buf_size,
            ftp_printf_t ftp_printf);

Use the FTP protocol to retrieve a file from a server. Only binary mode is supported. The filename can include a directory name. Only use unix style ‘/’ file separators, not ‘\’. The file is placed into buf. buf has maximum size buf_size. If the file is bigger than this, the transfer fails and FTP_TOOBIG is returned. Other error codes listed in the header can also be returned. If the transfer is successful the number of bytes received is returned.

ftp_put

int ftp_put(char * hostname, 
            char * username, 
            char * passwd, 
            char * filename, 
            char * buf, 
            unsigned buf_size,
            ftp_printf_t ftp_printf);

Use the FTP protocol to send a file to a server. Only binary mode is supported. The filename can include a directory name. Only use unix style ‘/’ file separators, not ‘\’. The contents of buf are placed into the file on the server. If an error occurs one of the codes listed will be returned. If the transfer is successful zero is returned.

ftpclient_printf

void ftpclient_printf(unsigned error, const char *fmt, ...);

ftp_get() and ftp_put take a pointer to a function to use for printing out diagnostic and error messages. This is a sample implementation which can be used if you don't want to implement the function yourself. error will be true when the message to print is an error message. Otherwise the message is diagnostic, eg. the commands sent and received from the server.