ftp_open(3)

NAME
ftp_open, ftp_read, ftp_write, ftp_lseek, ftp_close - FTP file access functions

SYNOPSIS
#include <libfget.h>

int ftp_open(FTPFILE **ftpfile, FTP *ftp, char *file, int mode);

int ftp_read(FTPFILE *ftpfile, char *buf, size_t bufsize);

int ftp_write(FTPFILE *ftpfile, char *buf, size_t bufsize);

int ftp_lseek(FTPFILE *ftpfile, off_t offset, int whence);

int ftp_close(FTPFILE *ftpfile);

VERSION
This man page documents version 1.2 of libfget.

DESCRIPTION
The ftp_open() function opens the file file on the FTP server associated with ftp. It allocates memory for an FTPFILE handle and changes ftpfile to point to the newly-allocated memory. The mode argument must be one of the following values:

O_RDONLY
    The file is opened in read-only mode.

O_WRONLY
    The file is opened in write-only mode.

The ftp_read() function reads at most bufsize bytes from the file associated with ftpfile and stores them in the buffer pointed to by buf.

The ftp_write() function writes bufsize bytes to the file associated with ftpfile from the buffer pointed to by buf.

The ftp_lseek() function repositions the offset of ftpfile to the argument offset according to the directive whence as follows:

SEEK_SET
    The offset is set to offset bytes.

SEEK_CUR
    The offset is set to its current location plus offset bytes.

The ftp_close() function closes the file and frees memory associated with ftpfile.

RETURN VALUE
The ftp_open(), ftp_lseek(), and ftp_close() functions return 0 on success, or -1 on error (and set errno).

The ftp_read() and ftp_write() functions return the number of characters read or written on success, or -1 on error (and set errno).

If errno is set to ECONNRESET, it indicates that the server shut down the connection. The caller is then responsible for calling ftp_quit() with the FTP_FASTCLOSE flag set.

NOTES
The ftp_lseek() function cannot be used if ftpfile was created with mode set to FTP_WRITE. As a consequence of this, it does not support the SEEK_END directive.

SEE ALSO
ftp_connect(3), open(2), read(2), write(2), lseek(2), close(2)