it.sauronsoftware.ftp4j
Class FTPClient

java.lang.Object
  extended by it.sauronsoftware.ftp4j.FTPClient

public class FTPClient
extends java.lang.Object

This class implements a FTP client. You can use an instance of this class to connect to a remote FTP site and do FTP operations like directory listing, file upload and download, resume a broken upload/download and so on. The common flow is: create the object, connect to a remote FTP site with the connect() method, authenticate with login(), do anything you need with the contents of the remote site, quit the site with disconnect(). A FTPClient object can handle a connection per time. Once you have used and disconnected a FTPClient object you can use it again to connect another FTP server.

Version:
1.7.1
Author:
Carlo Pelliccia

Field Summary
static int MLSD_ALWAYS
          The constant for the MLSD policy that causes the client to use always the MLSD command instead of LIST, also if the MLSD command is not explicitly supported by the server (the support is tested with the FEAT command).
static int MLSD_IF_SUPPORTED
          The constant for the MLSD policy that causes the client to use the MLSD command instead of LIST, but only if the MLSD command is explicitly supported by the server (the support is tested with the FEAT command).
static int MLSD_NEVER
          The constant for the MLSD policy that causes the client to use always the LIST command, also if the MLSD command is explicitly supported by the server (the support is tested with the FEAT command).
static int SECURITY_FTP
          The constant for the FTP security level.
static int SECURITY_FTPES
          The constant for the FTPES (FTP over explicit TLS/SSL) security level.
static int SECURITY_FTPS
          The constant for the FTPS (FTP over implicit TLS/SSL) security level.
static int TYPE_AUTO
          The constant for the AUTO file transfer type.
static int TYPE_BINARY
          The constant for the BINARY file transfer type.
static int TYPE_TEXTUAL
          The constant for the TEXTUAL file transfer type.
 
Constructor Summary
FTPClient()
          Builds and initializes the client.
 
Method Summary
 void abortCurrentConnectionAttempt()
          Aborts the current connection attempt.
 void abortCurrentDataTransfer(boolean sendAborCommand)
          If there's any ongoing data transfer operation, this method aborts it.
 void abruptlyCloseCommunication()
          This method causes the communication channel to be abruptly closed.
 void addCommunicationListener(FTPCommunicationListener listener)
          This method adds a FTPCommunicationListener to the object.
 void addListParser(FTPListParser listParser)
          This method adds a FTPListParser to the object.
 void append(java.io.File file)
          This method appends the contents of a local file to an existing file on the remote server.
 void append(java.io.File file, FTPDataTransferListener listener)
          This method uploads a file to the remote server.
 void append(java.lang.String fileName, java.io.InputStream inputStream, long streamOffset, FTPDataTransferListener listener)
          This method appends data to an existing file on the remote server.
 void changeAccount(java.lang.String account)
          Call this method to switch the user current account.
 void changeDirectory(java.lang.String path)
          This method changes the current working directory.
 void changeDirectoryUp()
          This method changes the current working directory to the parent one.
 java.lang.String[] connect(java.lang.String host)
          This method connects the client to the remote FTP host, using the default port value 21 (990 if security level is set to FTPS, see setSecurity(int)).
 java.lang.String[] connect(java.lang.String host, int port)
          This method connects the client to the remote FTP host.
 void createDirectory(java.lang.String directoryName)
          This method creates a new remote directory in the current working one.
 java.lang.String currentDirectory()
          This method asks and returns the current working directory.
 void deleteDirectory(java.lang.String path)
          This method deletes a remote directory.
 void deleteFile(java.lang.String path)
          This method deletes a remote file.
 void disconnect(boolean sendQuitCommand)
          This method disconnects from the remote server, optionally performing the QUIT procedure.
 void download(java.lang.String remoteFileName, java.io.File localFile)
          This method downloads a remote file from the server to a local file.
 void download(java.lang.String remoteFileName, java.io.File localFile, FTPDataTransferListener listener)
          This method downloads a remote file from the server to a local file.
 void download(java.lang.String remoteFileName, java.io.File localFile, long restartAt)
          This method resumes a download operation from the remote server to a local file.
 void download(java.lang.String remoteFileName, java.io.File localFile, long restartAt, FTPDataTransferListener listener)
          This method resumes a download operation from the remote server to a local file.
 void download(java.lang.String fileName, java.io.OutputStream outputStream, long restartAt, FTPDataTransferListener listener)
          This method resumes a download operation from the remote server.
 long fileSize(java.lang.String path)
          This method asks and returns a file size in bytes.
 long getAutoNoopTimeout()
          Returns the duration of the auto-noop timeout, in milliseconds.
 java.lang.String getCharset()
          Returns the name of the charset used to establish textual communications.
 FTPCommunicationListener[] getCommunicationListeners()
          This method returns a list with all the FTPCommunicationListener used by the client.
 FTPConnector getConnector()
          This method returns the connector used to connect the remote host.
 java.lang.String getHost()
          If the client is connected, it reports the remote host name or address.
 FTPListParser[] getListParsers()
          This method returns a list with all the FTPListParser used by the client.
 int getMLSDPolicy()
          This method returns the value suggesting how the client chooses whether to use or not the MLSD command (RFC 3659) instead of the base LIST command.
 java.lang.String getPassword()
          If the client is authenticated, it reports the authentication password.
 int getPort()
          If the client is connected, it reports the remote port number.
 int getSecurity()
          Returns the security level used by the client in the connection.
 javax.net.ssl.SSLSocketFactory getSSLSocketFactory()
          Returns the SSL socket factory used to negotiate SSL connections.
 FTPTextualExtensionRecognizer getTextualExtensionRecognizer()
          This method returns the textual extension recognizer used by the client.
 int getType()
          This method returns the value suggesting how the client encode and decode the contents during a data transfer.
 java.lang.String getUsername()
          If the client is authenticated, it reports the authentication username.
 java.lang.String[] help()
          This method calls the HELP command on the remote server, returning a list of lines with the help contents.
 boolean isAuthenticated()
          This method tests if this client is authenticated.
 boolean isCompressionEnabled()
          Checks whether the use of compression is enabled on the client-side.
 boolean isCompressionSupported()
          Checks whether the connected remote FTP server supports compressed data transfers (uploads, downloads, list operations etc.).
 boolean isConnected()
          This method tests if this client is connected to a remote FTP server.
 boolean isPassive()
          This method tests if this client works in passive FTP mode.
 boolean isResumeSupported()
          Checks whether the connected server explicitly supports resuming of broken data transfers.
 FTPFile[] list()
          This method lists the entries of the current working directory parsing the reply to a FTP LIST command.
 FTPFile[] list(java.lang.String fileSpec)
          This method lists the entries of the current working directory parsing the reply to a FTP LIST command.
 java.lang.String[] listNames()
          This method lists the entries of the current working directory with a FTP NLST command.
 void login(java.lang.String username, java.lang.String password)
          This method authenticates the user against the server.
 void login(java.lang.String username, java.lang.String password, java.lang.String account)
          This method authenticates the user against the server.
 void logout()
          This method performs a logout operation for the current user, leaving the connection open, thus it can be used to start a new user session.
 java.util.Date modifiedDate(java.lang.String path)
          This method asks and returns the last modification date of a file or directory.
 void noop()
          This method performs a "noop" operation with the server.
 void removeCommunicationListener(FTPCommunicationListener listener)
          This method removes a FTPCommunicationListener previously added to the object.
 void removeListParser(FTPListParser listParser)
          This method removes a FTPListParser previously added to the object.
 void rename(java.lang.String oldPath, java.lang.String newPath)
          This method renames a remote file or directory.
 FTPReply sendCustomCommand(java.lang.String command)
          This method sends a custom command to the server.
 FTPReply sendSiteCommand(java.lang.String command)
          This method sends a SITE specific command to the server.
 java.lang.String[] serverStatus()
          This method returns the remote server status, as the result of a FTP STAT command.
 void setAutoNoopTimeout(long autoNoopTimeout)
          Enable and disable the auto-noop feature.
 void setCharset(java.lang.String charset)
          Sets the name of the charset used to establish textual communications.
 void setCompressionEnabled(boolean compressionEnabled)
          Enables or disables the use of compression during any subsequent data transfer.
 void setConnector(FTPConnector connector)
          This method sets the connector used to connect the remote host.
 void setMLSDPolicy(int mlsdPolicy)
          This method lets the user control how the client chooses whether to use or not the MLSD command (RFC 3659) instead of the base LIST command.
 void setPassive(boolean passive)
          This method enables/disables the use of the passive mode.
 void setSecurity(int security)
          Sets the security level for the connection.
 void setSSLSocketFactory(javax.net.ssl.SSLSocketFactory sslSocketFactory)
          Sets the SSL socket factory used to negotiate SSL connections.
 void setTextualExtensionRecognizer(FTPTextualExtensionRecognizer textualExtensionRecognizer)
          This method sets the textual extension recognizer used by the client.
 void setType(int type)
          This methods sets how to treat the contents during a file transfer.
 java.lang.String toString()
           
 void upload(java.io.File file)
          This method uploads a file to the remote server.
 void upload(java.io.File file, FTPDataTransferListener listener)
          This method uploads a file to the remote server.
 void upload(java.io.File file, long restartAt)
          This method uploads a file to the remote server.
 void upload(java.io.File file, long restartAt, FTPDataTransferListener listener)
          This method uploads a file to the remote server.
 void upload(java.lang.String fileName, java.io.InputStream inputStream, long restartAt, long streamOffset, FTPDataTransferListener listener)
          This method uploads a content to the remote server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SECURITY_FTP

public static final int SECURITY_FTP
The constant for the FTP security level.

Since:
1.4
See Also:
Constant Field Values

SECURITY_FTPS

public static final int SECURITY_FTPS
The constant for the FTPS (FTP over implicit TLS/SSL) security level.

Since:
1.4
See Also:
Constant Field Values

SECURITY_FTPES

public static final int SECURITY_FTPES
The constant for the FTPES (FTP over explicit TLS/SSL) security level.

Since:
1.4
See Also:
Constant Field Values

TYPE_AUTO

public static final int TYPE_AUTO
The constant for the AUTO file transfer type. It lets the client pick between textual and binary types, depending on the extension of the file exchanged through a textual extension recognizer.

See Also:
Constant Field Values

TYPE_TEXTUAL

public static final int TYPE_TEXTUAL
The constant for the TEXTUAL file transfer type. It means that the data sent or received is treated as textual information. This implies charset conversion during the transfer.

See Also:
Constant Field Values

TYPE_BINARY

public static final int TYPE_BINARY
The constant for the BINARY file transfer type. It means that the data sent or received is treated as a binary stream. The data is taken "as is", without any charset conversion.

See Also:
Constant Field Values

MLSD_IF_SUPPORTED

public static final int MLSD_IF_SUPPORTED
The constant for the MLSD policy that causes the client to use the MLSD command instead of LIST, but only if the MLSD command is explicitly supported by the server (the support is tested with the FEAT command).

Since:
1.5
See Also:
Constant Field Values

MLSD_ALWAYS

public static final int MLSD_ALWAYS
The constant for the MLSD policy that causes the client to use always the MLSD command instead of LIST, also if the MLSD command is not explicitly supported by the server (the support is tested with the FEAT command).

Since:
1.5
See Also:
Constant Field Values

MLSD_NEVER

public static final int MLSD_NEVER
The constant for the MLSD policy that causes the client to use always the LIST command, also if the MLSD command is explicitly supported by the server (the support is tested with the FEAT command).

Since:
1.5
See Also:
Constant Field Values
Constructor Detail

FTPClient

public FTPClient()
Builds and initializes the client.

Method Detail

getConnector

public FTPConnector getConnector()
This method returns the connector used to connect the remote host.

Returns:
The connector used to connect the remote host.

setConnector

public void setConnector(FTPConnector connector)
This method sets the connector used to connect the remote host. Default one is a it.sauronsoftware.ftp4j.connectors.direct.DirectConnector instance.

Parameters:
connector - The connector used to connect the remote host.
See Also:
DirectConnector

setSSLSocketFactory

public void setSSLSocketFactory(javax.net.ssl.SSLSocketFactory sslSocketFactory)
Sets the SSL socket factory used to negotiate SSL connections.

Parameters:
sslSocketFactory - The SSL socket factory used to negotiate SSL connections.
Since:
1.4

getSSLSocketFactory

public javax.net.ssl.SSLSocketFactory getSSLSocketFactory()
Returns the SSL socket factory used to negotiate SSL connections.

Returns:
The SSL socket factory used to negotiate SSL connections.
Since:
1.4

setSecurity

public void setSecurity(int security)
                 throws java.lang.IllegalStateException,
                        java.lang.IllegalArgumentException
Sets the security level for the connection. This method should be called before starting a connection with a server. The security level must be expressed using one of the SECURITY_FTP, SECURITY_FTPS and SECURITY_FTPES costants. SECURITY_FTP, which is the default value, applies the basic FTP security level. SECURITY_FTPS applies the FTPS security level, which is FTP over implicit TLS/SSL. SECURITY_FTPES applies the FTPES security level, which is FTP over explicit TLS/SSL.

Parameters:
security - The security level.
Throws:
java.lang.IllegalStateException - If the client is already connected to a server.
java.lang.IllegalArgumentException - If the supplied security level is not valid.
Since:
1.4

getSecurity

public int getSecurity()
Returns the security level used by the client in the connection.

Returns:
The security level, which could be one of the SECURITY_FTP, SECURITY_FTPS and SECURITY_FTPES costants.
Since:
1.4

setPassive

public void setPassive(boolean passive)
This method enables/disables the use of the passive mode.

Parameters:
passive - If true the passive mode is enabled.

setType

public void setType(int type)
             throws java.lang.IllegalArgumentException
This methods sets how to treat the contents during a file transfer. The type supplied should be one of TYPE_AUTO, TYPE_TEXTUAL or TYPE_BINARY constants. Default value is TYPE_AUTO. TYPE_TEXTUAL means that the data sent or received is treated as textual information. This implies charset conversion during the transfer. TYPE_BINARY means that the data sent or received is treated as a binary stream. The data is taken "as is", without any charset conversion. TYPE_AUTO lets the client pick between textual and binary types, depending on the extension of the file exchanged, using a FTPTextualExtensionRecognizer instance, which could be set through the setTextualExtensionRecognizer method. The default recognizer is an instance of DefaultTextualExtensionRecognizer.

Parameters:
type - The type.
Throws:
java.lang.IllegalArgumentException - If the supplied type is not valid.
See Also:
setTextualExtensionRecognizer(FTPTextualExtensionRecognizer), DefaultTextualExtensionRecognizer

getType

public int getType()
This method returns the value suggesting how the client encode and decode the contents during a data transfer.

Returns:
The type as a numeric value. The value could be compared to the constants TYPE_AUTO, TYPE_BINARY and TYPE_TEXTUAL.

setMLSDPolicy

public void setMLSDPolicy(int mlsdPolicy)
                   throws java.lang.IllegalArgumentException
This method lets the user control how the client chooses whether to use or not the MLSD command (RFC 3659) instead of the base LIST command. The type supplied should be one of MLSD_IF_SUPPORTED, MLSD_ALWAYS or MLSD_NEVER constants. Default value is MLSD_IF_SUPPORTED. MLSD_IF_SUPPORTED means that the client should use the MLSD command only if it is explicitly supported by the server. MLSD_ALWAYS means that the client should use always the MLSD command, also if the MLSD command is not explicitly supported by the server MLSD_NEVER means that the client should use always only the LIST command, also if the MLSD command is explicitly supported by the server. The support for the MLSD command is tested by the client after the connection to the remote server, with the FEAT command.

Parameters:
mlsdPolicy - The MLSD policy.
Throws:
java.lang.IllegalArgumentException - If the supplied MLSD policy value is not valid.
Since:
1.5

getMLSDPolicy

public int getMLSDPolicy()
This method returns the value suggesting how the client chooses whether to use or not the MLSD command (RFC 3659) instead of the base LIST command.

Returns:
The MLSD policy as a numeric value. The value could be compared to the constants MLSD_IF_SUPPORTED, MLSD_ALWAYS and MLSD_NEVER.
Since:
1.5

getCharset

public java.lang.String getCharset()
Returns the name of the charset used to establish textual communications. If not null the client will use always the given charset. If null the client tries to auto-detect the server charset. If this attempt fails the client will use the machine current charset.

Returns:
The name of the charset used to establish textual communications.
Since:
1.1

setCharset

public void setCharset(java.lang.String charset)
Sets the name of the charset used to establish textual communications. If not null the client will use always the given charset. If null the client tries to auto-detect the server charset. If this attempt fails the client will use the machine current charset.

Parameters:
charset - The name of the charset used to establish textual communications.
Since:
1.1

isResumeSupported

public boolean isResumeSupported()
Checks whether the connected server explicitly supports resuming of broken data transfers.

Returns:
true if the server supports resuming, false otherwise.
Since:
1.5.1

isCompressionSupported

public boolean isCompressionSupported()
Checks whether the connected remote FTP server supports compressed data transfers (uploads, downloads, list operations etc.). If so, the compression of any subsequent data transfer (upload, download, list etc.) can be compressed, saving bandwidth. To enable compression call setCompressionEnabled(boolean) . The returned value is not significant if the client is not connected and authenticated.

Returns:
true if compression of data transfers is supported on the server-side, false otherwise.
Since:
1.5
See Also:
isCompressionEnabled()

setCompressionEnabled

public void setCompressionEnabled(boolean compressionEnabled)
Enables or disables the use of compression during any subsequent data transfer. Compression is enabled when both the supplied value and the isCompressionSupported()) returned value are true. The default value is false.

Parameters:
compressionEnabled - true to enable the use of compression during any subsequent file transfer, false to disable the feature.
Since:
1.5
See Also:
isCompressionSupported()

isCompressionEnabled

public boolean isCompressionEnabled()
Checks whether the use of compression is enabled on the client-side. Please note that compressed transfers are actually enabled only if both this method and isCompressionSupported() return true.

Returns:
true if compression is enabled, false otherwise.
Since:
1.5
See Also:
isCompressionSupported()

getTextualExtensionRecognizer

public FTPTextualExtensionRecognizer getTextualExtensionRecognizer()
This method returns the textual extension recognizer used by the client. Default one is DefaultTextualExtensionRecognizer.

Returns:
The textual extension recognizer used by the client.
See Also:
DefaultTextualExtensionRecognizer

setTextualExtensionRecognizer

public void setTextualExtensionRecognizer(FTPTextualExtensionRecognizer textualExtensionRecognizer)
This method sets the textual extension recognizer used by the client. The default one is DefaultTextualExtensionRecognizer. You can plug your own by implementing the FTPTextualExtensionRecognizer interface. For your convenience the ftp4j gives you another FTPTextualExtensionRecognizer implementation, which is ParametricTextualExtensionRecognizer.

Parameters:
textualExtensionRecognizer - The textual extension recognizer used by the client.
See Also:
DefaultTextualExtensionRecognizer, ParametricTextualExtensionRecognizer

isAuthenticated

public boolean isAuthenticated()
This method tests if this client is authenticated.

Returns:
true if this client is authenticated, false otherwise.

isConnected

public boolean isConnected()
This method tests if this client is connected to a remote FTP server.

Returns:
true if this client is connected to a remote FTP server, false otherwise.

isPassive

public boolean isPassive()
This method tests if this client works in passive FTP mode.

Returns:
true if this client is configured to work in passive FTP mode.

getHost

public java.lang.String getHost()
If the client is connected, it reports the remote host name or address.

Returns:
The remote host name or address.

getPort

public int getPort()
If the client is connected, it reports the remote port number.

Returns:
The remote port number.

getPassword

public java.lang.String getPassword()
If the client is authenticated, it reports the authentication password.

Returns:
The authentication password.

getUsername

public java.lang.String getUsername()
If the client is authenticated, it reports the authentication username.

Returns:
The authentication username.

setAutoNoopTimeout

public void setAutoNoopTimeout(long autoNoopTimeout)
Enable and disable the auto-noop feature. If the supplied value is greater than 0, the auto-noop feature is enabled, otherwise it is disabled. If positive, the field is used as a timeout value (expressed in milliseconds). If autoNoopDelay milliseconds has passed without any communication between the client and the server, a NOOP command is automaticaly sent to the server by the client. The default value for the auto noop delay is 0 (disabled).

Parameters:
autoNoopTimeout - The duration of the auto-noop timeout, in milliseconds. If 0 or less, the auto-noop feature is disabled.
Since:
1.5

getAutoNoopTimeout

public long getAutoNoopTimeout()
Returns the duration of the auto-noop timeout, in milliseconds. If 0 or less, the auto-noop feature is disabled.

Returns:
The duration of the auto-noop timeout, in milliseconds. If 0 or less, the auto-noop feature is disabled.
Since:
1.5

addCommunicationListener

public void addCommunicationListener(FTPCommunicationListener listener)
This method adds a FTPCommunicationListener to the object.

Parameters:
listener - The listener.

removeCommunicationListener

public void removeCommunicationListener(FTPCommunicationListener listener)
This method removes a FTPCommunicationListener previously added to the object.

Parameters:
listener - The listener to be removed.

getCommunicationListeners

public FTPCommunicationListener[] getCommunicationListeners()
This method returns a list with all the FTPCommunicationListener used by the client.

Returns:
A list with all the FTPCommunicationListener used by the client.

addListParser

public void addListParser(FTPListParser listParser)
This method adds a FTPListParser to the object.

Parameters:
listParser - The list parser.

removeListParser

public void removeListParser(FTPListParser listParser)
This method removes a FTPListParser previously added to the object.

Parameters:
listParser - The list parser to be removed.

getListParsers

public FTPListParser[] getListParsers()
This method returns a list with all the FTPListParser used by the client.

Returns:
A list with all the FTPListParsers used by the client.

connect

public java.lang.String[] connect(java.lang.String host)
                           throws java.lang.IllegalStateException,
                                  java.io.IOException,
                                  FTPIllegalReplyException,
                                  FTPException
This method connects the client to the remote FTP host, using the default port value 21 (990 if security level is set to FTPS, see setSecurity(int)).

Parameters:
host - The hostname of the remote server.
Returns:
The server welcome message, one line per array element.
Throws:
java.lang.IllegalStateException - If the client is already connected to a remote host.
java.io.IOException - If an I/O occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the server refuses the connection.

connect

public java.lang.String[] connect(java.lang.String host,
                                  int port)
                           throws java.lang.IllegalStateException,
                                  java.io.IOException,
                                  FTPIllegalReplyException,
                                  FTPException
This method connects the client to the remote FTP host.

Parameters:
host - The host name or address of the remote server.
port - The port listened by the remote server.
Returns:
The server welcome message, one line per array element.
Throws:
java.lang.IllegalStateException - If the client is already connected to a remote host.
java.io.IOException - If an I/O occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the server refuses the connection.

abortCurrentConnectionAttempt

public void abortCurrentConnectionAttempt()
Aborts the current connection attempt. It can be called by a secondary thread while the client is blocked in a connect() call. The connect() method will exit with an IOException.

Since:
1.7

disconnect

public void disconnect(boolean sendQuitCommand)
                throws java.lang.IllegalStateException,
                       java.io.IOException,
                       FTPIllegalReplyException,
                       FTPException
This method disconnects from the remote server, optionally performing the QUIT procedure.

Parameters:
sendQuitCommand - If true the QUIT procedure with the server will be performed, otherwise the connection is abruptly closed by the client without sending any advice to the server.
Throws:
java.lang.IllegalStateException - If the client is not connected to a remote host.
java.io.IOException - If an I/O occurs (can be thrown only if sendQuitCommand is true).
FTPIllegalReplyException - If the server replies in an illegal way (can be thrown only if sendQuitCommand is true).
FTPException - If the server refuses the QUIT command (can be thrown only if sendQuitCommand is true).

abruptlyCloseCommunication

public void abruptlyCloseCommunication()
This method causes the communication channel to be abruptly closed. Use it carefully, since this one is not thread-safe. It is given as an "emergency brake" to close the control connection when it is blocked. A thread-safe solution for the same purpose is a call to disconnect(false).

See Also:
disconnect(boolean)

login

public void login(java.lang.String username,
                  java.lang.String password)
           throws java.lang.IllegalStateException,
                  java.io.IOException,
                  FTPIllegalReplyException,
                  FTPException
This method authenticates the user against the server.

Parameters:
username - The username.
password - The password (if none set it to null).
Throws:
java.lang.IllegalStateException - If the client is not connected. Call the connect() method before!
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If login fails.

login

public void login(java.lang.String username,
                  java.lang.String password,
                  java.lang.String account)
           throws java.lang.IllegalStateException,
                  java.io.IOException,
                  FTPIllegalReplyException,
                  FTPException
This method authenticates the user against the server.

Parameters:
username - The username.
password - The password (if none set it to null).
account - The account (if none set it to null). Be careful: some servers don't implement this feature.
Throws:
java.lang.IllegalStateException - If the client is not connected. Call the connect() method before!
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If login fails.

logout

public void logout()
            throws java.lang.IllegalStateException,
                   java.io.IOException,
                   FTPIllegalReplyException,
                   FTPException
This method performs a logout operation for the current user, leaving the connection open, thus it can be used to start a new user session. Be careful with this: some FTP servers don't implement this feature, even though it is a standard FTP one.

Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.

noop

public void noop()
          throws java.lang.IllegalStateException,
                 java.io.IOException,
                 FTPIllegalReplyException,
                 FTPException
This method performs a "noop" operation with the server.

Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If login fails.

sendCustomCommand

public FTPReply sendCustomCommand(java.lang.String command)
                           throws java.lang.IllegalStateException,
                                  java.io.IOException,
                                  FTPIllegalReplyException
This method sends a custom command to the server. Don't use this method to send standard commands already supported by the client: this should cause unexpected results.

Parameters:
command - The command line.
Returns:
The reply supplied by the server, parsed and served in an object way mode.
Throws:
java.lang.IllegalStateException - If this client is not connected.
java.io.IOException - If a I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.

sendSiteCommand

public FTPReply sendSiteCommand(java.lang.String command)
                         throws java.lang.IllegalStateException,
                                java.io.IOException,
                                FTPIllegalReplyException
This method sends a SITE specific command to the server.

Parameters:
command - The site command.
Returns:
The reply supplied by the server, parsed and served in an object way mode.
Throws:
java.lang.IllegalStateException - If this client is not connected.
java.io.IOException - If a I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.

changeAccount

public void changeAccount(java.lang.String account)
                   throws java.lang.IllegalStateException,
                          java.io.IOException,
                          FTPIllegalReplyException,
                          FTPException
Call this method to switch the user current account. Be careful with this: some FTP servers don't implement this feature, even though it is a standard FTP one.

Parameters:
account - The account.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If login fails.

currentDirectory

public java.lang.String currentDirectory()
                                  throws java.lang.IllegalStateException,
                                         java.io.IOException,
                                         FTPIllegalReplyException,
                                         FTPException
This method asks and returns the current working directory.

Returns:
path The path to the current working directory.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.

changeDirectory

public void changeDirectory(java.lang.String path)
                     throws java.lang.IllegalStateException,
                            java.io.IOException,
                            FTPIllegalReplyException,
                            FTPException
This method changes the current working directory.

Parameters:
path - The path to the new working directory.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.

changeDirectoryUp

public void changeDirectoryUp()
                       throws java.lang.IllegalStateException,
                              java.io.IOException,
                              FTPIllegalReplyException,
                              FTPException
This method changes the current working directory to the parent one.

Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.

modifiedDate

public java.util.Date modifiedDate(java.lang.String path)
                            throws java.lang.IllegalStateException,
                                   java.io.IOException,
                                   FTPIllegalReplyException,
                                   FTPException
This method asks and returns the last modification date of a file or directory.

Parameters:
path - The path to the file or the directory.
Returns:
The file/directory last modification date.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.

fileSize

public long fileSize(java.lang.String path)
              throws java.lang.IllegalStateException,
                     java.io.IOException,
                     FTPIllegalReplyException,
                     FTPException
This method asks and returns a file size in bytes.

Parameters:
path - The path to the file.
Returns:
The file size in bytes.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.

rename

public void rename(java.lang.String oldPath,
                   java.lang.String newPath)
            throws java.lang.IllegalStateException,
                   java.io.IOException,
                   FTPIllegalReplyException,
                   FTPException
This method renames a remote file or directory. It can also be used to move a file or a directory. In example:
 client.rename("oldname", "newname"); // This one renames
 
 client.rename("the/old/path/oldname", "/a/new/path/newname"); // This one moves
 

Parameters:
oldPath - The current path of the file (or directory).
newPath - The new path for the file (or directory).
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.

deleteFile

public void deleteFile(java.lang.String path)
                throws java.lang.IllegalStateException,
                       java.io.IOException,
                       FTPIllegalReplyException,
                       FTPException
This method deletes a remote file.

Parameters:
path - The path to the file.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.

deleteDirectory

public void deleteDirectory(java.lang.String path)
                     throws java.lang.IllegalStateException,
                            java.io.IOException,
                            FTPIllegalReplyException,
                            FTPException
This method deletes a remote directory.

Parameters:
path - The path to the directory.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.

createDirectory

public void createDirectory(java.lang.String directoryName)
                     throws java.lang.IllegalStateException,
                            java.io.IOException,
                            FTPIllegalReplyException,
                            FTPException
This method creates a new remote directory in the current working one.

Parameters:
directoryName - The name of the new directory.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.

help

public java.lang.String[] help()
                        throws java.lang.IllegalStateException,
                               java.io.IOException,
                               FTPIllegalReplyException,
                               FTPException
This method calls the HELP command on the remote server, returning a list of lines with the help contents.

Returns:
The help contents, splitted by line.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.

serverStatus

public java.lang.String[] serverStatus()
                                throws java.lang.IllegalStateException,
                                       java.io.IOException,
                                       FTPIllegalReplyException,
                                       FTPException
This method returns the remote server status, as the result of a FTP STAT command.

Returns:
The remote server status, splitted by line.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.

list

public FTPFile[] list(java.lang.String fileSpec)
               throws java.lang.IllegalStateException,
                      java.io.IOException,
                      FTPIllegalReplyException,
                      FTPException,
                      FTPDataTransferException,
                      FTPAbortedException,
                      FTPListParseException
This method lists the entries of the current working directory parsing the reply to a FTP LIST command. The response to the LIST command is parsed through the FTPListParser objects registered on the client. The distribution of ftp4j contains some standard parsers already registered on every FTPClient object created. If they don't work in your case (a FTPListParseException is thrown), you can build your own parser implementing the FTPListParser interface and add it to the client by calling its addListParser() method. Calling this method blocks the current thread until the operation is completed. The operation could be interrupted by another thread calling abortCurrentDataTransfer(). The list() method will break with a FTPAbortedException.

Parameters:
fileSpec - A file filter string. Depending on the server implementation, wildcard characters could be accepted.
Returns:
The list of the files (and directories) in the current working directory.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.
FTPDataTransferException - If a I/O occurs in the data transfer connection. If you receive this exception the transfer failed, but the main connection with the remote FTP server is in theory still working.
FTPAbortedException - If operation is aborted by another thread.
FTPListParseException - If none of the registered parsers can handle the response sent by the server.
Since:
1.2
See Also:
FTPListParser, addListParser(FTPListParser), getListParsers(), abortCurrentDataTransfer(boolean), listNames()

list

public FTPFile[] list()
               throws java.lang.IllegalStateException,
                      java.io.IOException,
                      FTPIllegalReplyException,
                      FTPException,
                      FTPDataTransferException,
                      FTPAbortedException,
                      FTPListParseException
This method lists the entries of the current working directory parsing the reply to a FTP LIST command. The response to the LIST command is parsed through the FTPListParser objects registered on the client. The distribution of ftp4j contains some standard parsers already registered on every FTPClient object created. If they don't work in your case (a FTPListParseException is thrown), you can build your own parser implementing the FTPListParser interface and add it to the client by calling its addListParser() method. Calling this method blocks the current thread until the operation is completed. The operation could be interrupted by another thread calling abortCurrentDataTransfer(). The list() method will break with a FTPAbortedException.

Returns:
The list of the files (and directories) in the current working directory.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.
FTPDataTransferException - If a I/O occurs in the data transfer connection. If you receive this exception the transfer failed, but the main connection with the remote FTP server is in theory still working.
FTPAbortedException - If operation is aborted by another thread.
FTPListParseException - If none of the registered parsers can handle the response sent by the server.
See Also:
FTPListParser, addListParser(FTPListParser), getListParsers(), abortCurrentDataTransfer(boolean), listNames()

listNames

public java.lang.String[] listNames()
                             throws java.lang.IllegalStateException,
                                    java.io.IOException,
                                    FTPIllegalReplyException,
                                    FTPException,
                                    FTPDataTransferException,
                                    FTPAbortedException,
                                    FTPListParseException
This method lists the entries of the current working directory with a FTP NLST command. The response consists in an array of string, each one reporting the name of a file or a directory placed in the current working directory. For a more detailed directory listing procedure look at the list() method. Calling this method blocks the current thread until the operation is completed. The operation could be interrupted by another thread calling abortCurrentDataTransfer(). The listNames() method will break with a FTPAbortedException.

Returns:
The list of the files (and directories) in the current working directory.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.
FTPDataTransferException - If a I/O occurs in the data transfer connection. If you receive this exception the transfer failed, but the main connection with the remote FTP server is in theory still working.
FTPAbortedException - If operation is aborted by another thread.
FTPListParseException - If none of the registered parsers can handle the response sent by the server.
See Also:
abortCurrentDataTransfer(boolean), list()

upload

public void upload(java.io.File file)
            throws java.lang.IllegalStateException,
                   java.io.FileNotFoundException,
                   java.io.IOException,
                   FTPIllegalReplyException,
                   FTPException,
                   FTPDataTransferException,
                   FTPAbortedException
This method uploads a file to the remote server. Calling this method blocks the current thread until the operation is completed. The operation could be interrupted by another thread calling abortCurrentDataTransfer(). The method will break with a FTPAbortedException.

Parameters:
file - The file to upload.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.FileNotFoundException - If the supplied file cannot be found.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.
FTPDataTransferException - If a I/O occurs in the data transfer connection. If you receive this exception the transfer failed, but the main connection with the remote FTP server is in theory still working.
FTPAbortedException - If operation is aborted by another thread.
See Also:
abortCurrentDataTransfer(boolean)

upload

public void upload(java.io.File file,
                   FTPDataTransferListener listener)
            throws java.lang.IllegalStateException,
                   java.io.FileNotFoundException,
                   java.io.IOException,
                   FTPIllegalReplyException,
                   FTPException,
                   FTPDataTransferException,
                   FTPAbortedException
This method uploads a file to the remote server. Calling this method blocks the current thread until the operation is completed. The operation could be interrupted by another thread calling abortCurrentDataTransfer(). The method will break with a FTPAbortedException.

Parameters:
file - The file to upload.
listener - The listener for the operation. Could be null.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.FileNotFoundException - If the supplied file cannot be found.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.
FTPDataTransferException - If a I/O occurs in the data transfer connection. If you receive this exception the transfer failed, but the main connection with the remote FTP server is in theory still working.
FTPAbortedException - If operation is aborted by another thread.
See Also:
abortCurrentDataTransfer(boolean)

upload

public void upload(java.io.File file,
                   long restartAt)
            throws java.lang.IllegalStateException,
                   java.io.FileNotFoundException,
                   java.io.IOException,
                   FTPIllegalReplyException,
                   FTPException,
                   FTPDataTransferException,
                   FTPAbortedException
This method uploads a file to the remote server. Calling this method blocks the current thread until the operation is completed. The operation could be interrupted by another thread calling abortCurrentDataTransfer(). The method will break with a FTPAbortedException.

Parameters:
file - The file to upload.
restartAt - The restart point (number of bytes already uploaded). Use isResumeSupported() to check if the server supports resuming of broken data transfers.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.FileNotFoundException - If the supplied file cannot be found.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.
FTPDataTransferException - If a I/O occurs in the data transfer connection. If you receive this exception the transfer failed, but the main connection with the remote FTP server is in theory still working.
FTPAbortedException - If operation is aborted by another thread.
See Also:
abortCurrentDataTransfer(boolean)

upload

public void upload(java.io.File file,
                   long restartAt,
                   FTPDataTransferListener listener)
            throws java.lang.IllegalStateException,
                   java.io.FileNotFoundException,
                   java.io.IOException,
                   FTPIllegalReplyException,
                   FTPException,
                   FTPDataTransferException,
                   FTPAbortedException
This method uploads a file to the remote server. Calling this method blocks the current thread until the operation is completed. The operation could be interrupted by another thread calling abortCurrentDataTransfer(). The method will break with a FTPAbortedException.

Parameters:
file - The file to upload.
restartAt - The restart point (number of bytes already uploaded). Use isResumeSupported() to check if the server supports resuming of broken data transfers.
listener - The listener for the operation. Could be null.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.FileNotFoundException - If the supplied file cannot be found.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.
FTPDataTransferException - If a I/O occurs in the data transfer connection. If you receive this exception the transfer failed, but the main connection with the remote FTP server is in theory still working.
FTPAbortedException - If operation is aborted by another thread.
See Also:
abortCurrentDataTransfer(boolean)

upload

public void upload(java.lang.String fileName,
                   java.io.InputStream inputStream,
                   long restartAt,
                   long streamOffset,
                   FTPDataTransferListener listener)
            throws java.lang.IllegalStateException,
                   java.io.IOException,
                   FTPIllegalReplyException,
                   FTPException,
                   FTPDataTransferException,
                   FTPAbortedException
This method uploads a content to the remote server. Calling this method blocks the current thread until the operation is completed. The operation could be interrupted by another thread calling abortCurrentDataTransfer(). The method will break with a FTPAbortedException.

Parameters:
fileName - The name of the remote file.
inputStream - The source of data.
restartAt - The restart point (number of bytes already uploaded). Use isResumeSupported() to check if the server supports resuming of broken data transfers.
streamOffset - The offset to skip in the stream.
listener - The listener for the operation. Could be null.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.
FTPDataTransferException - If a I/O occurs in the data transfer connection. If you receive this exception the transfer failed, but the main connection with the remote FTP server is in theory still working.
FTPAbortedException - If operation is aborted by another thread.
See Also:
abortCurrentDataTransfer(boolean)

append

public void append(java.io.File file)
            throws java.lang.IllegalStateException,
                   java.io.FileNotFoundException,
                   java.io.IOException,
                   FTPIllegalReplyException,
                   FTPException,
                   FTPDataTransferException,
                   FTPAbortedException
This method appends the contents of a local file to an existing file on the remote server. Calling this method blocks the current thread until the operation is completed. The operation could be interrupted by another thread calling abortCurrentDataTransfer(). The method will break with a FTPAbortedException.

Parameters:
file - The local file whose contents will be appended to the remote file.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.FileNotFoundException - If the supplied file cannot be found.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.
FTPDataTransferException - If a I/O occurs in the data transfer connection. If you receive this exception the transfer failed, but the main connection with the remote FTP server is in theory still working.
FTPAbortedException - If operation is aborted by another thread.
Since:
1.6
See Also:
abortCurrentDataTransfer(boolean)

append

public void append(java.io.File file,
                   FTPDataTransferListener listener)
            throws java.lang.IllegalStateException,
                   java.io.FileNotFoundException,
                   java.io.IOException,
                   FTPIllegalReplyException,
                   FTPException,
                   FTPDataTransferException,
                   FTPAbortedException
This method uploads a file to the remote server. Calling this method blocks the current thread until the operation is completed. The operation could be interrupted by another thread calling abortCurrentDataTransfer(). The method will break with a FTPAbortedException.

Parameters:
file - The local file whose contents will be appended to the remote file.
listener - The listener for the operation. Could be null.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.FileNotFoundException - If the supplied file cannot be found.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.
FTPDataTransferException - If a I/O occurs in the data transfer connection. If you receive this exception the transfer failed, but the main connection with the remote FTP server is in theory still working.
FTPAbortedException - If operation is aborted by another thread.
Since:
1.6
See Also:
abortCurrentDataTransfer(boolean)

append

public void append(java.lang.String fileName,
                   java.io.InputStream inputStream,
                   long streamOffset,
                   FTPDataTransferListener listener)
            throws java.lang.IllegalStateException,
                   java.io.IOException,
                   FTPIllegalReplyException,
                   FTPException,
                   FTPDataTransferException,
                   FTPAbortedException
This method appends data to an existing file on the remote server. Calling this method blocks the current thread until the operation is completed. The operation could be interrupted by another thread calling abortCurrentDataTransfer(). The method will break with a FTPAbortedException.

Parameters:
fileName - The name of the remote file.
inputStream - The source of data.
streamOffset - The offset to skip in the stream.
listener - The listener for the operation. Could be null.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.
FTPDataTransferException - If a I/O occurs in the data transfer connection. If you receive this exception the transfer failed, but the main connection with the remote FTP server is in theory still working.
FTPAbortedException - If operation is aborted by another thread.
Since:
1.6
See Also:
abortCurrentDataTransfer(boolean)

download

public void download(java.lang.String remoteFileName,
                     java.io.File localFile)
              throws java.lang.IllegalStateException,
                     java.io.FileNotFoundException,
                     java.io.IOException,
                     FTPIllegalReplyException,
                     FTPException,
                     FTPDataTransferException,
                     FTPAbortedException
This method downloads a remote file from the server to a local file. Calling this method blocks the current thread until the operation is completed. The operation could be interrupted by another thread calling abortCurrentDataTransfer(). The method will break with a FTPAbortedException.

Parameters:
remoteFileName - The name of the file to download.
localFile - The local file.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.FileNotFoundException - If the supplied file cannot be found.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.
FTPDataTransferException - If a I/O occurs in the data transfer connection. If you receive this exception the transfer failed, but the main connection with the remote FTP server is in theory still working.
FTPAbortedException - If operation is aborted by another thread.
See Also:
abortCurrentDataTransfer(boolean)

download

public void download(java.lang.String remoteFileName,
                     java.io.File localFile,
                     FTPDataTransferListener listener)
              throws java.lang.IllegalStateException,
                     java.io.FileNotFoundException,
                     java.io.IOException,
                     FTPIllegalReplyException,
                     FTPException,
                     FTPDataTransferException,
                     FTPAbortedException
This method downloads a remote file from the server to a local file. Calling this method blocks the current thread until the operation is completed. The operation could be interrupted by another thread calling abortCurrentDataTransfer(). The method will break with a FTPAbortedException.

Parameters:
remoteFileName - The name of the file to download.
localFile - The local file.
listener - The listener for the operation. Could be null.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.FileNotFoundException - If the supplied file cannot be found.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.
FTPDataTransferException - If a I/O occurs in the data transfer connection. If you receive this exception the transfer failed, but the main connection with the remote FTP server is in theory still working.
FTPAbortedException - If operation is aborted by another thread.
See Also:
abortCurrentDataTransfer(boolean)

download

public void download(java.lang.String remoteFileName,
                     java.io.File localFile,
                     long restartAt)
              throws java.lang.IllegalStateException,
                     java.io.FileNotFoundException,
                     java.io.IOException,
                     FTPIllegalReplyException,
                     FTPException,
                     FTPDataTransferException,
                     FTPAbortedException
This method resumes a download operation from the remote server to a local file. Calling this method blocks the current thread until the operation is completed. The operation could be interrupted by another thread calling abortCurrentDataTransfer(). The method will break with a FTPAbortedException.

Parameters:
remoteFileName - The name of the file to download.
localFile - The local file.
restartAt - The restart point (number of bytes already downloaded). Use isResumeSupported() to check if the server supports resuming of broken data transfers.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.FileNotFoundException - If the supplied file cannot be found.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.
FTPDataTransferException - If a I/O occurs in the data transfer connection. If you receive this exception the transfer failed, but the main connection with the remote FTP server is in theory still working.
FTPAbortedException - If operation is aborted by another thread.
See Also:
abortCurrentDataTransfer(boolean)

download

public void download(java.lang.String remoteFileName,
                     java.io.File localFile,
                     long restartAt,
                     FTPDataTransferListener listener)
              throws java.lang.IllegalStateException,
                     java.io.FileNotFoundException,
                     java.io.IOException,
                     FTPIllegalReplyException,
                     FTPException,
                     FTPDataTransferException,
                     FTPAbortedException
This method resumes a download operation from the remote server to a local file. Calling this method blocks the current thread until the operation is completed. The operation could be interrupted by another thread calling abortCurrentDataTransfer(). The method will break with a FTPAbortedException.

Parameters:
remoteFileName - The name of the file to download.
localFile - The local file.
restartAt - The restart point (number of bytes already downloaded). Use isResumeSupported() to check if the server supports resuming of broken data transfers.
listener - The listener for the operation. Could be null.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.FileNotFoundException - If the supplied file cannot be found.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.
FTPDataTransferException - If a I/O occurs in the data transfer connection. If you receive this exception the transfer failed, but the main connection with the remote FTP server is in theory still working.
FTPAbortedException - If operation is aborted by another thread.
See Also:
abortCurrentDataTransfer(boolean)

download

public void download(java.lang.String fileName,
                     java.io.OutputStream outputStream,
                     long restartAt,
                     FTPDataTransferListener listener)
              throws java.lang.IllegalStateException,
                     java.io.IOException,
                     FTPIllegalReplyException,
                     FTPException,
                     FTPDataTransferException,
                     FTPAbortedException
This method resumes a download operation from the remote server. Calling this method blocks the current thread until the operation is completed. The operation could be interrupted by another thread calling abortCurrentDataTransfer(). The method will break with a FTPAbortedException.

Parameters:
fileName - The name of the remote file.
outputStream - The destination stream of data read during the download.
restartAt - The restart point (number of bytes already downloaded). Use isResumeSupported() to check if the server supports resuming of broken data transfers.
listener - The listener for the operation. Could be null.
Throws:
java.lang.IllegalStateException - If the client is not connected or not authenticated.
java.io.IOException - If an I/O error occurs.
FTPIllegalReplyException - If the server replies in an illegal way.
FTPException - If the operation fails.
FTPDataTransferException - If a I/O occurs in the data transfer connection. If you receive this exception the transfer failed, but the main connection with the remote FTP server is in theory still working.
FTPAbortedException - If operation is aborted by another thread.
See Also:
abortCurrentDataTransfer(boolean)

abortCurrentDataTransfer

public void abortCurrentDataTransfer(boolean sendAborCommand)
                              throws java.io.IOException,
                                     FTPIllegalReplyException
If there's any ongoing data transfer operation, this method aborts it.

Parameters:
sendAborCommand - If true the client will negotiate the abort procedure with the server, through the standard FTP ABOR command. Otherwise the open data transfer connection will be closed without any advise has sent to the server.
Throws:
java.io.IOException - If the ABOR command cannot be sent due to any I/O error. This could happen only if force is false.
FTPIllegalReplyException - If the server reply to the ABOR command is illegal. This could happen only if force is false.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object