FtpClient provides all the functionalities of a typical FTP
client, like storing or retrieving files, listing or creating directories.
A typical usage would consist of connecting the client to the server,
log in, issue a few commands then logout.
Here is a code example:
FtpClient cl = FtpClient.create();
cl.connect("ftp.gnu.org").login("anonymous", "[email protected]".toCharArray())).changeDirectory("pub/gnu");
Iterator<FtpDirEntry> dir = cl.listFiles();
while (dir.hasNext()) {
FtpDirEntry f = dir.next();
System.err.println(f.getName());
}
cl.close();
}
Error reporting: There are, mostly, two families of errors that
can occur during an FTP session. The first kind are the network related issues
like a connection reset, and they are usually fatal to the session, meaning,
in all likelihood the connection to the server has been lost and the session
should be restarted from scratch. These errors are reported by throwing an
IOException. The second kind are the errors reported by the FTP server,
like when trying to download a non-existing file for example. These errors
are usually non fatal to the session, meaning more commands can be sent to the
server. In these cases, a FtpProtocolException is thrown.
It should be noted that this is not a thread-safe API, as it wouldn't make too much sense, due to the very sequential nature of FTP, to provide a client able to be manipulated from multiple threads.
| Modifier and Type | Class and Description |
|---|---|
| public static enum |
| Modifier and Type | Field and Description |
|---|---|
| private static final int |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public abstract FtpClient | |
| public abstract FtpClient | Returns: this FtpClientThe number of bytes to allocate. size)Sends the "Allocate" ( |
| public abstract FtpClient | Returns: this FtpClientA name, InputStream String containing the name of the remote file
to append to.The local)InputStream providing access to the data
to be appended.Sends the APPE command to the server in order to transfer a data stream passed in argument and append it to the content of the specified remote file. |
| public abstract FtpClient | Returns: this FtpClientpath of the directory to CD to. remoteDirectory)Changes to a specific directory on a remote FTP server |
| public abstract FtpClient | Returns: this FtpClientChanges to the parent directory, sending the CDUP command to the server. |
| public abstract void | |
| public abstract FtpClient | Returns: this FtpClientSome methods do not wait until completion before returning, so this method can be called to wait until completion. |
| public abstract FtpClient | Returns: this FtpClientthe address of the destination server dest)Connects the |
| public abstract FtpClient | Returns: this FtpClientthe address of the destination server dest, int the value, in milliseconds, to use as a connection timeout timeout)Connects the FtpClient to the specified destination server. |
| public static FtpClient | |
| public static FtpClient | Returns: The createdFtpClientthe dest)InetSocketAddress to connect to.Creates an instance of FtpClient and connects it to the specified address. |
| public static FtpClient | |
| public static final int | |
| public abstract FtpClient | Returns: this FtpClienta name)String containing the name of the file
to delete.Deletes a file on the server. |
| public abstract FtpClient | Returns: This FtpClienttrue to force passive mode.Enables, or disables, the use of the passive mode. |
| public abstract FtpClient | Returns: this FtpClientSends a |
| public abstract int | Returns: the value, in milliseconds, of the current connect timeout.Returns the current default connection timeout value. |
| public abstract List | Returns: aList of Strings describing the
supported additional featuresSends the |
| public abstract FtpClient | Returns: this FtpClienta name, OutputStream String containing the name of the file to
retrieve from the server.the local)OutputStream the file should be written to.Retrieves a file from the ftp server and writes its content to the specified
|
| public abstract InputStream | Returns: thejava. from the data connectionthe name of the remote file name)Retrieves a file from the ftp server, using the |
| public abstract String | Returns: aString containing the text sent back by the
server, or null if the command failed.the command for which the help is requested or
cmd)null for the general helpSends the |
| public abstract String | Returns: the name the latest transferred file remote name, ornull if that information is unavailable.Returns, when available, the remote name of the last transferred file. |
| public abstract Date | Returns: aDate representing the last modification time
or null if the server returned an error, which
can be checked with getLastReplyCode().a path)String containing the pathname of the file.Issues the |
| public abstract FtpReplyCode | Returns: the lastReplyCode ornull if none were received yet.Returns the last reply code sent by the server. |
| public abstract String | Returns: the message string, which can be quite long, last returned by the server, ornull if no response were received yet.Returns the last response string sent by the server. |
| public abstract long | Returns: the size of the latest transfer or -1 if either there was no transfer or the information was unavailable.Returns, when available, the size of the latest started transfer. |
| public abstract Proxy | Returns: theProxy, this client is using, or null
if none is used.Get the proxy of this FtpClient |
| public abstract int | Returns: the value, in milliseconds, of the current read timeout.Returns the current read timeout value. |
| public abstract SocketAddress | |
| public abstract long | Returns: along containing the size of the file or -1 if
the server returned an error, which can be checked with
getLastReplyCode().a path)String containing the pathname of the
file.Issues the |
| public abstract String | |
| public abstract String | Returns: aString describing the OS, or null
if the operation was not successful.Sends a System ( |
| public abstract String | Returns: aString containing the message the server
returned during connection or null.Returns the Welcome string the server sent during initial connection. |
| public abstract String | Returns: aString containing the current working directoryRetrieve the server current working directory using the PWD command. |
| public abstract boolean | Returns: true if the client is connected.Tests whether this client is connected or not to a server. |
| public abstract boolean | Returns: true if the client has already completed a login.Checks whether the client is logged in to the server or not. |
| public abstract boolean | Returns: true if the passive mode has been enabled.Tests whether passive mode is enabled. |
| public abstract InputStream | |
| public abstract Iterator | Returns: anIterator of files or null if the
command failed.the pathname of the directory to list or path)null
for the current working directory.Issues a |
| public abstract FtpClient | |
| public abstract FtpClient | |
| public abstract FtpClient | Returns: this FtpClienta name)String containing the name of the directory
to create.Creates a new directory on the server. |
| public abstract InputStream | |
| public abstract FtpClient | |
| public FtpClient | Returns: this FtpClientthe name of the remote file to write. name, InputStream the local)InputStream that points to the data to
transfer.Transfers a file from the client to the server (aka a put)
by sending the STOR or STOU command, depending on the
|
| public abstract FtpClient | Returns: this FtpClientthe name of the remote file to write. name, InputStream the local, boolean InputStream that points to the data to
transfer.true if the remote file should be unique
(i.e. not already existing), false otherwise.Transfers a file from the client to the server (aka a put) by sending the STOR command. |
| public OutputStream | putFileStream(String
the name of the remote file to write. name)Transfers a file from the client to the server (aka a put)
by sending the STOR command, and returns the |
| public abstract OutputStream | Returns: thejava. from the data connection.the name of the remote file to write. name, boolean true if the remote files should be unique,
in which case the STOU command will be used.Transfers a file from the client to the server (aka a put)
by sending the STOR or STOU command, depending on the
|
| public abstract FtpClient | |
| public abstract FtpClient | Returns: this FtpClienta name)String containing the name of the directory
to remove.Removes a directory on the server. |
| public abstract FtpClient | |
| public FtpClient | |
| public FtpClient | |
| public abstract FtpClient | Returns: This FtpClientthe timeout value, in milliseconds, to use for the connect
operation. A value of zero or less, means use the default timeout. timeout)Sets the default timeout value to use when connecting to the server, |
| public abstract FtpClient | Returns: this FtpClientThe p)FtpDirParser to use.Sets the parser used to handle the directory output to the specified one. |
| public abstract FtpClient | |
| public abstract FtpClient | Returns: This FtpClientthe timeout value, in milliseconds, to use for the read
operation. A value of zero or less, means use the default timeout. timeout)Sets the timeout value to use when reading from the server, |
| public abstract FtpClient | Returns: this FtpClientthe offset in the remote file at which to start the next
transfer. This must be a value greater than or equal to zero. offset)Sets the restart offset to the specified value. |
| public abstract FtpClient | Returns: This FtpClientthe typeTransferType to use.Changes the transfer type (binary, ascii, ebcdic) and issue the proper command (e.g. TYPE A) to the server. |
| public abstract FtpClient | |
| public abstract FtpClient | |
| public abstract FtpClient | Returns: this FtpClienta struct)String containing the name of the
structure to mount.Sends the "Structure Mount" ( |
| public abstract FtpClient | Returns: this FtpClientAttempts to use Kerberos GSSAPI as an authentication mechanism with the ftp server. |