ftp

MODULE

ftp

MODULE SUMMARY

A File Transfer Protocol client

DESCRIPTION

The ftp module implements a client for file transfer
according to a subset of the File Transfer Protocol (see RFC959).

Starting from inets version 4.4.1 the ftp
client will always try to use passive ftp mode and only resort
to active ftp mode if this fails. There is a start option
mode where this default behavior
may be changed.

There are two ways to start an ftp client. One is using the
Inets service framework
and the other is to start it directy as a standalone process
using the open function.

In addition to the ordinary functions for receiving and sending
files (see recv/2, recv/3, send/2 and
send/3) there are functions for receiving remote files as
binaries (see recv_bin/2) and for sending binaries to to be
stored as remote files (see send_bin/3).

There is also a set of functions for sending and receiving
contiguous parts of a file to be stored in a remote file (for send
see send_chunk_start/2, send_chunk/2 and
send_chunk_end/1 and for receive see
recv_chunk_start/2 and recv_chunk/).

The particular return values of the functions below depend very
much on the implementation of the FTP server at the remote
host. In particular the results from ls and nlist
varies. Often real errors are not reported as errors by ls,
even if for instance a file or directory does not
exist. nlist is usually more strict, but some
implementations have the peculiar behaviour of responding with an
error, if the request is a listing of the contents of directory
which exists but is empty.

The FTP client can be started and stopped dynamically in runtime by
calling the Inets application API
inets:start(ftpc, ServiceConfig),
or inets:start(ftpc, ServiceConfig, How), and
inets:stop(ftpc, Pid).
See inets(3) for more info.

Below follows a description of
the available configuration options.

{host, Host}

Host = string() | ip_address()

{port, Port}

Port = integer() > 0

Default is 21.

{mode, Mode}

Mode = active | passive

Default is passive.

{verbose, Verbose}

Verbose = boolean()

This determines if the FTP communication should be
verbose or not.

Default is false.

{debug, Debug}

Debug = trace | debug | disable

Debugging using the dbg toolkit.

Default is disable.

{ipfamily, IpFamily}

IpFamily = inet | inet6 | inet6fb4

With inet6fb4 the client behaves as before
(it tries to use IPv6 and only if that does not work, it
uses IPv4).

Default is inet (IPv4).

{timeout, Timeout}

Timeout = non_neg_integer()

Connection timeout.

Default is 60000 (milliseconds).

{dtimeout, DTimeout}

DTimeout = non_neg_integer() | infinity

Data Connect timeout.
The time the client will wait for the server to connect to the
data socket.

Default is infinity.

{progress, Progress}

Progress = ignore | {CBModule, CBFunction, InitProgress}

CBModule = atom(), CBFunction = atom()

InitProgress = term()

Default is ignore.

The progress option is intended to be used by applications that
want to create some type of progress report such as a progress bar in
a GUI. The default value for the progress option is ignore
e.i. the option is not used. When the progress option is
specified the following will happen when ftp:send/[3,4] or
ftp:recv/[3,4] are called.

Before a file is transfered the following call will
be made to indicate the start of the file transfer and how big
the file is. The return value of the callback function
should be a new value for the UserProgressTerm that will
bu used as input next time the callback function is
called.

CBModule:CBFunction(InitProgress, File, {file_size, FileSize})

Every time a chunk of bytes is transfered the
following call will be made:

Alas for remote files it is not possible for ftp to determine the
file size in a platform independent way. In this case the size
will be unknown and it is left to the application to find
out the size.

Note

The callback is made by a middleman process, hence the
file transfer will not be affected by the code in the progress
callback function. If the callback should crash this will be
detected by the ftp connection process that will print an
info-report and then go one as if the progress option was set
to ignore.

The file transfer type is set to the default of the FTP server
when the session is opened. This is usually ASCCI-mode.

The current local working directory (cf. lpwd/1) is set to
the value reported by file:get_cwd/1. the wanted
local directory.

The return value Pid is used as a reference to the
newly created ftp client in all other functions, and they should
be called by the process that created the connection. The ftp
client process monitors the process that created it and
will terminate if that process terminates.

Transfers the file LocalFile to the remote server. If
RemoteFile is specified, the name of the remote file that the
file will be appended to is set to RemoteFile; otherwise
the name is set to LocalFile If the file does not exists the
file will be created.

Pathname can be a directory, a group of files or
even a file. The Pathname string can contain wildcard(s).

nlist/1 implies the user's current remote directory.

The format of Listing is a stream of
file names, where each name is separated by <CRLF> or
<NL>. Contrary to the ls function, the purpose of
nlist is to make it possible for a program to
automatically process file name information.

This function is used to start a standalone ftp client process
(without the inets service framework) and
open a session with the FTP server at Host.

If the option {tls, tls_options()} is present, the ftp session will be transported over tls (ftps, see
RFC 4217). The list tls_options() may be empty. The function ssl:connect/3 is used for securing both the control connection and the data sessions.

FTPLine = string() - Note the telnet end of line characters, from the ftp protocol definition, CRLF e.g. "\\r\\n" has been removed.

Sends an arbitrary FTP command and returns verbatimly a list
of the lines sent back by the FTP server. This functions is
intended to give an application accesses to FTP commands
that are server specific or that may not be provided by
this FTP client.

Note

FTP commands that require a data connection can not be
successfully issued with this function.

The possible error reasons and the corresponding diagnostic strings
returned by formaterror/1 are as follows:

echunk

Synchronisation error during chunk sending.

A call has been made to send_chunk/2 or
send_chunk_end/1, before a call to
send_chunk_start/2; or a call has been made to another
transfer function during chunk sending, i.e. before a call
to send_chunk_end/1.

eclosed

The session has been closed.

econn

Connection to remote server prematurely closed.

ehost

Host not found, FTP server not found, or connection rejected
by FTP server.

elogin

User not logged in.

enotbinary

Term is not a binary.

epath

No such file or directory, or directory already exists, or
permission denied.