com.myjavaworld.ftp
Class DefaultFTPClient

java.lang.Object
  extended by com.myjavaworld.ftp.DefaultFTPClient
All Implemented Interfaces:
FTPClient, FTPConstants
Direct Known Subclasses:
AS400FTPClient

public class DefaultFTPClient
extends Object
implements FTPClient, FTPConstants

The default implementation of FTPClient. Works well with most of the UNIX type FTP servers.

Version:
2.0
Author:
Sai Pullabhotla, psai [at] jMethods [dot] com

Field Summary
protected  int bufferSize
          Buffer size for transferring data over the network.
protected  boolean connected
          A flag that tells we are still connected to the remote host.
protected  ControlConnection controlConnection
          A Control Connection object for sending commands and receiving replies.
protected  boolean dataChannelUnencrypted
          A flag to determine if the data channel will be encrypted or not.
protected  DataConnection dataConnection
          A DataConnection object used for transferring data to/from the remote system.
protected  String explicitSSLProtocol
          The SSL protocol to use for negotiating Explicit SSL connections.
protected  EventListenerList listenerList
          List of registered listeners.
protected  ListParser listParser
          A ListParser object used to parse the directory listing produced by the remote host.
protected  boolean loggedIn
          A flag that tells if we are logged in to the remote host.
protected  int mode
          Data transfer mode.
protected  boolean passive
          Whether or not to open data connections in passive mode.
protected  boolean passiveIPSubstitutionEnabled
          Flag that determines if passive connections IP address should be substituted with the original server's IP address.
protected  Proxy proxy
          The proxy server to use when connecting to the FTP server
protected  String reply
          Stores that last reply received from the remote host.
protected  SSLContext sslContext
          SSL context
protected  int sslUsage
          SSL usage of this ftp client.
protected  int structure
          Structure.
protected  int timeout
          Timeout for this FTPClient.
protected  int type
          Data representation type.
protected  RemoteFile workingDirectory
          Keep track of the current working directory on the remote host.
 
Fields inherited from interface com.myjavaworld.ftp.FTPConstants
DEFAULT_BUFFER_SIZE, DEFAULT_IMPLICIT_SSL_PORT, DEFAULT_MODE, DEFAULT_PORT, DEFAULT_STRUCTURE, DEFAULT_TIMEOUT, DEFAULT_TYPE, EOL, MODE_BLOCK, MODE_COMPRESSED, MODE_STREAM, STRUCTURE_FILE, STRUCTURE_PAGE, STRUCTURE_RECORD, TYPE_ASCII, TYPE_BINARY, TYPE_EBCDIC, TYPE_IMAGE, TYPE_LOCAL, USE_EXPLICIT_SSL, USE_IMPLICIT_SSL, USE_NO_SSL, USE_SSL_IF_AVAILABLE
 
Constructor Summary
DefaultFTPClient()
          Constructs an DefaultFTPClient object that is not connected to any host.
 
Method Summary
 void abort()
          Sends an abort command to the remote host.
 void addControlConnectionListener(ControlConnectionListener l)
          Adds a listener that will be notified about the activities of ControlConnection associated with this FTPClient .
 void addDataConnectionListener(DataConnectionListener l)
          Adds a DataConnection Listener to this FTPClient.
 void addFTPConnectionListener(FTPConnectionListener l)
          Adds the given FTPConnectionListener to the list of registered listeners.
 void allocate(long bytes)
          Allocates the specified number of bytes on the remote system.
 void close()
          Closes the control and data connections associated with this FTPClient.
 void connect(FTPHost ftpHost)
          Connects and logs in to the FTP host.
 void connect(String host)
          Connects to the specified remote host host on the default FTP port.
 void connect(String host, int port)
          Connects to the specfied remote host host, on the specified port number port.
 void createDirectory(RemoteFile dir)
          Creates the specified remote directory dir on the remote host.
 void createFile(RemoteFile file)
          Creates an empty file with the given name on the remote host.
 void delete(RemoteFile path)
          Deletes the specified path from the remote system.
 void deleteDirectory(RemoteFile dir)
          Deletes the specified directory dir on the remote system.
 void deleteFile(RemoteFile file)
          Deletes the specified file, file from the remote system.
 void disconnect()
          Sends a quit command to the remote system and closes the control connection and data connection associated with this FTPClient.
 void download(RemoteFile source, File destination, int type, boolean append)
          Copies the contents of the source to the local file destination.
 String executeCommand(String command)
          Executes the given command returns the response back.
protected  void fireConnectionClosed(FTPConnectionEvent evt)
          Fires the connection closed event to all registered listeners.
protected  void fireConnectionOpened(FTPConnectionEvent evt)
          Fires the ConnectionOpened event to all registered listeners.
 int getBufferSize()
          Returns the current buffer size being used by this FTPClient .
 String getExplicitSSLProtocol()
          Returns the SSL protocol that is in use for negotiating Explicit SSL connections.
 String getHelp()
          Executes the HELP command on the remote host and returns the response back.
 EventListenerList getListenerList()
          Returns the list of registered listeners.
 ListParser getListParser()
          Returns the current ListParser in use by this FTPClient.
 InetAddress getLocalAddress()
          Returns the InetAddress of the local host.
 String getLocalHost()
          Returns the host name or IP address of the local host.
 String getLocalIPAddress()
          Returns the IP address of the local host in xxx.xxx.xxx.xxx format.
 int getLocalPort()
          Returns the local port number used by the control connection.
 int getMode()
          Returns the current mode in use.
 Proxy getProxy()
          Returns the current proxy configuration, if any.
 InetAddress getRemoteAddress()
          Returns the Address of the remote host.
 String getRemoteHost()
          Returns the fully qaulified domain name of the remote host.
 String getRemoteIPAddress()
          Returns the IP address of the remote host in xxx.xxx.xxx.xxx format.
 int getRemotePort()
          Returns the remote port number to which the ControlConnection is established.
 SSLContext getSSLContext()
          Gets the SSLContext of this FTPclient.
 int getSSLUsage()
          Returns the SSL usage of this FTPClient.
 int getStructure()
          Returns the current structure in use.
 String getSystemInfo()
          Returns the remote host's information by executing the SYST command.
 int getTimeout()
          Returns the timeout setting of this FTP client.
 int getType()
          Returns the current data representation type in use.
 RemoteFile getWorkingDirectory()
          Returns the current working directory.
 boolean isConnected()
          Checks whether or not this FTPClient is still connected to to the remote host.
 boolean isDataChannelUnencrypted()
          Tells whether or not the data channel encryption is ON.
 boolean isLoggedIn()
          Checks wherher or not this client is logged in.
 boolean isPassive()
          Tells whether or not the data connectons are opned in passive mode.
 boolean isPassiveIPSubstitutionEnabled()
          Tells whether or not the substitution of passive IP address is enabled.
 boolean isSecured()
          Tells whether this connection is secured.
 RemoteFile[] list()
          Retrieves the contents (children) of the current working directory.
 RemoteFile[] list(Filter filter)
          Retrieves the children of the current working directory.
 RemoteFile[] list(RemoteFile dir)
          Returns the direct children of the specified directory.
 RemoteFile[] list(RemoteFile dir, Filter filter)
          Returns the direct children of the specified directory.
 void login(String user, String password)
          Logs in to the remote host with the specified user id and password.
 void login(String user, String password, String account)
          Logs in to the remote host with the specified user ID, pasword and account.
 void mountStructure(String path)
          Sends a SMNT command with the specified path to mount.
 void noop()
          Sends a No-Operation command to the remote system.
 void reinitialize()
          Sends a reinitialize command to the remote host.
 void removeControlConnectionListener(ControlConnectionListener l)
          Removes the given listener from the list of registered listenerrs.
 void removeDataConnectionListener(DataConnectionListener l)
          Removes the given data connection listener from the registered list of listeners.
 void removeFTPConnectionListener(FTPConnectionListener l)
          Unregisters the given listener from the list of listeners.
 void rename(RemoteFile from, RemoteFile to)
          Renames a file or directory, from to to.
 void restart(long bytes)
          Sends a RESTART command to the remote host with the specified number of bytes.
 void setBufferSize(int bufferSize)
          Sets the buffer size to use for transferring data over the data connection.
 void setDataChannelUnencrypted(boolean dataChannelUnencrypted)
          Sets/unsets the flag to encrypt the data channel.
 void setExplicitSSLProtocol(String protocol)
          Sets the SSL protocol to use when negotiating an Explicit SSL connection.
 void setListParser(ListParser listParser)
          Sets the ListParser to the specified listParser .ListParser objects are used to parsre the contents of a remote directory in to RemoteFile objects.
 void setMode(int mode)
          Sets the mode in which data is transferred to the given mode .
 void setPassive(boolean passive)
          If true, marks that the data is to be transgerrred over a passive data connection.
 void setPassiveIPSubstitutionEnabled(boolean enable)
          Sets or unsets the flag that determines whether or not to ignore the response (the IP address portion) of PASV command and substitute it with the original server IP address when making a PASSIVE data connection.
 void setProxy(Proxy proxy)
          Sets the proxy server to use when making the control/data connections.
 void setSiteParameter(String param)
          Sends a SITE command with the specified parameter(s).
 void setSSLContext(SSLContext sslContext)
          Sets the SSLContext of this FTPClient to the given context.
 void setSSLUsage(int sslUsage)
          Sets the SSL usage of this client to the given value.
 void setStructure(int structure)
          Sets the structure to the specified structure.
 void setTimeout(int timeout)
          Sets the timeout for this FTPClient to the specified timeout.
 RemoteFile setToParentDirectory()
          Sets the remote working directory to the parent directory of the current working directory.
 void setType(int type)
          Sets the data representation type to the given type.
 RemoteFile setWorkingDirectory(RemoteFile dir)
          Sets the remote working directory to the specified directory dir.
 void upload(File source, RemoteFile destination, int type, boolean append, long skip)
          copies the contents of local file source to the specified remote file destination.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

timeout

protected int timeout
Timeout for this FTPClient.


bufferSize

protected int bufferSize
Buffer size for transferring data over the network.


type

protected int type
Data representation type. For e.g. ASCII, Binary etc.


mode

protected int mode
Data transfer mode. For e.g. Stream, Block etc.


structure

protected int structure
Structure. For e.g. File, Record, Page etc.


passive

protected boolean passive
Whether or not to open data connections in passive mode.


connected

protected boolean connected
A flag that tells we are still connected to the remote host.


loggedIn

protected boolean loggedIn
A flag that tells if we are logged in to the remote host.


workingDirectory

protected RemoteFile workingDirectory
Keep track of the current working directory on the remote host.


reply

protected String reply
Stores that last reply received from the remote host.


controlConnection

protected ControlConnection controlConnection
A Control Connection object for sending commands and receiving replies.


dataConnection

protected DataConnection dataConnection
A DataConnection object used for transferring data to/from the remote system.


listParser

protected ListParser listParser
A ListParser object used to parse the directory listing produced by the remote host.


sslUsage

protected int sslUsage
SSL usage of this ftp client.


sslContext

protected SSLContext sslContext
SSL context


dataChannelUnencrypted

protected boolean dataChannelUnencrypted
A flag to determine if the data channel will be encrypted or not.


explicitSSLProtocol

protected String explicitSSLProtocol
The SSL protocol to use for negotiating Explicit SSL connections.


listenerList

protected EventListenerList listenerList
List of registered listeners.


passiveIPSubstitutionEnabled

protected boolean passiveIPSubstitutionEnabled
Flag that determines if passive connections IP address should be substituted with the original server's IP address.


proxy

protected Proxy proxy
The proxy server to use when connecting to the FTP server

Constructor Detail

DefaultFTPClient

public DefaultFTPClient()
Constructs an DefaultFTPClient object that is not connected to any host.

Method Detail

setTimeout

public void setTimeout(int timeout)
Description copied from interface: FTPClient
Sets the timeout for this FTPClient to the specified timeout. Timeout is the amount of time an FTPClient waits for a server's reponse. If the server does not respond with in the timeout period, Implementations should close the connection. The timeout must be set before calling the connect methods. If an FTP client is already connected to a remote host, the new time out may be ignored by implementation classes.

Specified by:
setTimeout in interface FTPClient
Parameters:
timeout - Timeout in milli seconds.

getTimeout

public int getTimeout()
Description copied from interface: FTPClient
Returns the timeout setting of this FTP client.

Specified by:
getTimeout in interface FTPClient
Returns:
Timeout of this FTPClient.

setBufferSize

public void setBufferSize(int bufferSize)
Description copied from interface: FTPClient
Sets the buffer size to use for transferring data over the data connection.

Specified by:
setBufferSize in interface FTPClient
Parameters:
bufferSize - Buffer size to use for transferring data over the data connection.

getBufferSize

public int getBufferSize()
Description copied from interface: FTPClient
Returns the current buffer size being used by this FTPClient .

Specified by:
getBufferSize in interface FTPClient
Returns:
Current buffer size in use.

setListParser

public void setListParser(ListParser listParser)
Description copied from interface: FTPClient
Sets the ListParser to the specified listParser .ListParser objects are used to parsre the contents of a remote directory in to RemoteFile objects.

Specified by:
setListParser in interface FTPClient
Parameters:
listParser - The ListParser to use to parse the contents of a remote directory.

getListParser

public ListParser getListParser()
Description copied from interface: FTPClient
Returns the current ListParser in use by this FTPClient.

Specified by:
getListParser in interface FTPClient
Returns:
ListParser in use.

setSSLUsage

public void setSSLUsage(int sslUsage)
Description copied from interface: FTPClient
Sets the SSL usage of this client to the given value. The possible values are:

Specified by:
setSSLUsage in interface FTPClient
Parameters:
sslUsage - SSL usage parameter to set.

getSSLUsage

public int getSSLUsage()
Description copied from interface: FTPClient
Returns the SSL usage of this FTPClient.

Specified by:
getSSLUsage in interface FTPClient
Returns:
SSL usage of this FTPClient. Possible values are:
  • FTPConstants.USE_NO_SSL
  • FTPConstants.USE_SSL_IF_AVAILABLE
  • FTPConstants.USE_EXPLICIT_SSL
  • FTPConstants.USE_IMPLICIT_SSL

setSSLContext

public void setSSLContext(SSLContext sslContext)
Description copied from interface: FTPClient
Sets the SSLContext of this FTPClient to the given context.

Specified by:
setSSLContext in interface FTPClient
Parameters:
sslContext - SSLContext

getSSLContext

public SSLContext getSSLContext()
Description copied from interface: FTPClient
Gets the SSLContext of this FTPclient.

Specified by:
getSSLContext in interface FTPClient
Returns:
SSLContext of this FTPClient. May return null, if no context was set.

setDataChannelUnencrypted

public void setDataChannelUnencrypted(boolean dataChannelUnencrypted)
Description copied from interface: FTPClient
Sets/unsets the flag to encrypt the data channel.

Specified by:
setDataChannelUnencrypted in interface FTPClient
Parameters:
dataChannelUnencrypted - whether or not to encrypt the data channel.

isDataChannelUnencrypted

public boolean isDataChannelUnencrypted()
Description copied from interface: FTPClient
Tells whether or not the data channel encryption is ON.

Specified by:
isDataChannelUnencrypted in interface FTPClient
Returns:
true, if the data channel encryption os ON, false, otherwise.

isSecured

public boolean isSecured()
Description copied from interface: FTPClient
Tells whether this connection is secured.

Specified by:
isSecured in interface FTPClient
Returns:
true, if this connection is secured. false, othherwise.

setExplicitSSLProtocol

public void setExplicitSSLProtocol(String protocol)
Description copied from interface: FTPClient
Sets the SSL protocol to use when negotiating an Explicit SSL connection. The specified protocol string will be sent (to the FTP server) as a parameter to the AUTH command. Valid values are "SSL" and "TLS", however, this method does not restrict clients from using other values.

Specified by:
setExplicitSSLProtocol in interface FTPClient
Parameters:
protocol - the security protocol to use when negotiating an Explicit SSL connection.

getExplicitSSLProtocol

public String getExplicitSSLProtocol()
Description copied from interface: FTPClient
Returns the SSL protocol that is in use for negotiating Explicit SSL connections.

Specified by:
getExplicitSSLProtocol in interface FTPClient
Returns:
the SSL protocol that is in use for negotiating Explicit SSL connections. If the setExplicitSSLProtocol(string protocol) method is not called, this method returns the default value "SSL".

connect

public void connect(String host)
             throws FTPException,
                    ConnectionException
Description copied from interface: FTPClient
Connects to the specified remote host host on the default FTP port.

Specified by:
connect in interface FTPClient
Parameters:
host - Host name or IP address of the remote host.
Throws:
FTPException
ConnectionException

connect

public void connect(String host,
                    int port)
             throws FTPException,
                    ConnectionException
Description copied from interface: FTPClient
Connects to the specfied remote host host, on the specified port number port.

Specified by:
connect in interface FTPClient
Parameters:
host - Host name or IP address of the remote host.
port - Port number to connect to.
Throws:
FTPException
ConnectionException

connect

public void connect(FTPHost ftpHost)
             throws FTPException,
                    ConnectionException
Description copied from interface: FTPClient
Connects and logs in to the FTP host.

Specified by:
connect in interface FTPClient
Parameters:
ftpHost - Remote FTP host to connect to.
Throws:
FTPException
ConnectionException

isConnected

public boolean isConnected()
Description copied from interface: FTPClient
Checks whether or not this FTPClient is still connected to to the remote host.

Specified by:
isConnected in interface FTPClient
Returns:
true, if this FTPClient is still connected to the remote host. Otherwise, false.

login

public void login(String user,
                  String password)
           throws FTPException,
                  ConnectionException
Description copied from interface: FTPClient
Logs in to the remote host with the specified user id and password.

Specified by:
login in interface FTPClient
Parameters:
user - User ID.
password - Password.
Throws:
FTPException
ConnectionException

login

public void login(String user,
                  String password,
                  String account)
           throws FTPException,
                  ConnectionException
Description copied from interface: FTPClient
Logs in to the remote host with the specified user ID, pasword and account. Not all FTP servers need Account information.

Specified by:
login in interface FTPClient
Parameters:
user - User ID.
password - Password.
account - Account Name.
Throws:
FTPException
ConnectionException

isLoggedIn

public boolean isLoggedIn()
Description copied from interface: FTPClient
Checks wherher or not this client is logged in.

Specified by:
isLoggedIn in interface FTPClient
Returns:
true, if this client is logged in to the remote host. false otherwise.

setWorkingDirectory

public RemoteFile setWorkingDirectory(RemoteFile dir)
                               throws FTPException,
                                      ConnectionException
Description copied from interface: FTPClient
Sets the remote working directory to the specified directory dir. Clients must send a PWD command after sending the CWD command to make sure that the working directory has changed.

Specified by:
setWorkingDirectory in interface FTPClient
Parameters:
dir - New remote working directory to set.
Returns:
Working directory after the execution of this method.
Throws:
FTPException
ConnectionException

setToParentDirectory

public RemoteFile setToParentDirectory()
                                throws FTPException,
                                       ConnectionException
Description copied from interface: FTPClient
Sets the remote working directory to the parent directory of the current working directory.

Specified by:
setToParentDirectory in interface FTPClient
Returns:
working directory after the execution of this method.
Throws:
FTPException
ConnectionException

getWorkingDirectory

public RemoteFile getWorkingDirectory()
                               throws FTPException,
                                      ConnectionException
Description copied from interface: FTPClient
Returns the current working directory.

Specified by:
getWorkingDirectory in interface FTPClient
Returns:
Current remote working directory.
Throws:
FTPException
ConnectionException

setType

public void setType(int type)
             throws FTPException,
                    ConnectionException
Description copied from interface: FTPClient
Sets the data representation type to the given type.

Specified by:
setType in interface FTPClient
Parameters:
type - New data representation type to set. Possible types are -
  • FTPConstants.TYPE_ASCII
  • FTPConstants.TYPE_BINARY
  • FTPConstants.TYPE_IMAGE
  • FTPConstants.TYPE_EBCDIC
  • FTPConstants.TYPE_LOCAL
Throws:
FTPException
ConnectionException

getType

public int getType()
Description copied from interface: FTPClient
Returns the current data representation type in use.

Specified by:
getType in interface FTPClient
Returns:
current data representation type.

setStructure

public void setStructure(int structure)
                  throws FTPException,
                         ConnectionException
Description copied from interface: FTPClient
Sets the structure to the specified structure.

Specified by:
setStructure in interface FTPClient
Parameters:
structure - New structure to set. Possible structure type are -
  • FTPConstants.STRUCTURE_FILE
  • FTPConstants.STRUCTURE_RECORD
  • FTPConstants.STRUCTURE_PAGE
Throws:
FTPException
ConnectionException

getStructure

public int getStructure()
Description copied from interface: FTPClient
Returns the current structure in use.

Specified by:
getStructure in interface FTPClient
Returns:
current structure.

setMode

public void setMode(int mode)
             throws FTPException,
                    ConnectionException
Description copied from interface: FTPClient
Sets the mode in which data is transferred to the given mode .

Specified by:
setMode in interface FTPClient
Parameters:
mode - The new mode to set. Possible modes are -
  • FTPConstants.MODE_STREAM
  • FTPConstants.MODE_BLOCK
  • FTPConstants.MODE_COMPRESSED
Throws:
FTPException
ConnectionException

getMode

public int getMode()
Description copied from interface: FTPClient
Returns the current mode in use.

Specified by:
getMode in interface FTPClient
Returns:
Current mode in use.

setPassive

public void setPassive(boolean passive)
Description copied from interface: FTPClient
If true, marks that the data is to be transgerrred over a passive data connection.

Specified by:
setPassive in interface FTPClient
Parameters:
passive - Value true marks that the data is to be transferred over a passive data connection. Otherwise, over an active data connection.

isPassive

public boolean isPassive()
Description copied from interface: FTPClient
Tells whether or not the data connectons are opned in passive mode. This method will be consulted every time when there a need to open a data connection.

Specified by:
isPassive in interface FTPClient
Returns:
true if in passive mode. Otherwise, false.

createDirectory

public void createDirectory(RemoteFile dir)
                     throws FTPException,
                            ConnectionException
Description copied from interface: FTPClient
Creates the specified remote directory dir on the remote host.

Specified by:
createDirectory in interface FTPClient
Parameters:
dir - New directory to create.
Throws:
FTPException
ConnectionException

deleteDirectory

public void deleteDirectory(RemoteFile dir)
                     throws FTPException,
                            ConnectionException
Description copied from interface: FTPClient
Deletes the specified directory dir on the remote system. Most FTP servers would not allow the deletion of a directory unless it is empty. It is the responsibility of the clients to delete the children of the directory before attempting to delete a directory.

Specified by:
deleteDirectory in interface FTPClient
Parameters:
dir - Directory to delete.
Throws:
FTPException
ConnectionException

deleteFile

public void deleteFile(RemoteFile file)
                throws FTPException,
                       ConnectionException
Description copied from interface: FTPClient
Deletes the specified file, file from the remote system.

Specified by:
deleteFile in interface FTPClient
Parameters:
file - File to be deleted.
Throws:
FTPException
ConnectionException

delete

public void delete(RemoteFile path)
            throws FTPException,
                   ConnectionException
Description copied from interface: FTPClient
Deletes the specified path from the remote system. If the path is a directory (as determined by RemoteFile.isDirectory()) , then deleteDirectory() method will be called with path as an argument. Otherwise, deleteFile() method will be called with path as an argument.

Specified by:
delete in interface FTPClient
Parameters:
path - The file to delete.
Throws:
FTPException
ConnectionException

rename

public void rename(RemoteFile from,
                   RemoteFile to)
            throws FTPException,
                   ConnectionException
Description copied from interface: FTPClient
Renames a file or directory, from to to.

Specified by:
rename in interface FTPClient
Parameters:
from - The file to be renamed.
to - New file name.
Throws:
FTPException
ConnectionException

noop

public void noop()
          throws FTPException,
                 ConnectionException
Description copied from interface: FTPClient
Sends a No-Operation command to the remote system.

Specified by:
noop in interface FTPClient
Throws:
FTPException
ConnectionException

abort

public void abort()
           throws FTPException,
                  ConnectionException
Description copied from interface: FTPClient
Sends an abort command to the remote host.

Specified by:
abort in interface FTPClient
Throws:
FTPException
ConnectionException

reinitialize

public void reinitialize()
                  throws FTPException,
                         ConnectionException
Description copied from interface: FTPClient
Sends a reinitialize command to the remote host. Clients may need to login after executing this method.

Specified by:
reinitialize in interface FTPClient
Throws:
FTPException
ConnectionException

disconnect

public void disconnect()
                throws FTPException,
                       ConnectionException
Description copied from interface: FTPClient
Sends a quit command to the remote system and closes the control connection and data connection associated with this FTPClient.

Specified by:
disconnect in interface FTPClient
Throws:
FTPException
ConnectionException

close

public void close()
Description copied from interface: FTPClient
Closes the control and data connections associated with this FTPClient. This method should usually be called after a network error ocuurs in order to clean up the resources. Under normal conditions, the clients are recommended to call disconnect method.

Specified by:
close in interface FTPClient

allocate

public void allocate(long bytes)
              throws FTPException,
                     ConnectionException
Description copied from interface: FTPClient
Allocates the specified number of bytes on the remote system.

Specified by:
allocate in interface FTPClient
Parameters:
bytes - Number of bytes to allocate for this FTPClient.
Throws:
FTPException
ConnectionException

restart

public void restart(long bytes)
             throws FTPException,
                    ConnectionException
Description copied from interface: FTPClient
Sends a RESTART command to the remote host with the specified number of bytes.

Specified by:
restart in interface FTPClient
Parameters:
bytes - number of bytes to skip in the Input/Output stream.
Throws:
FTPException
ConnectionException

getSystemInfo

public String getSystemInfo()
                     throws FTPException,
                            ConnectionException
Description copied from interface: FTPClient
Returns the remote host's information by executing the SYST command.

Specified by:
getSystemInfo in interface FTPClient
Returns:
remote host's system information. The informaion returned will vary from FTP server to server.
Throws:
FTPException
ConnectionException

getHelp

public String getHelp()
               throws FTPException,
                      ConnectionException
Description copied from interface: FTPClient
Executes the HELP command on the remote host and returns the response back.

Specified by:
getHelp in interface FTPClient
Returns:
Response to HELP command.
Throws:
FTPException
ConnectionException

setSiteParameter

public void setSiteParameter(String param)
                      throws FTPException,
                             ConnectionException
Description copied from interface: FTPClient
Sends a SITE command with the specified parameter(s).

Specified by:
setSiteParameter in interface FTPClient
Parameters:
param - Parameters or the SITE command.
Throws:
FTPException
ConnectionException

mountStructure

public void mountStructure(String path)
                    throws FTPException,
                           ConnectionException
Description copied from interface: FTPClient
Sends a SMNT command with the specified path to mount.

Specified by:
mountStructure in interface FTPClient
Parameters:
path - New path structure to mount.
Throws:
FTPException
ConnectionException

executeCommand

public String executeCommand(String command)
                      throws FTPException,
                             ConnectionException
Description copied from interface: FTPClient
Executes the given command returns the response back.

Specified by:
executeCommand in interface FTPClient
Parameters:
command - Command to execute.
Returns:
Response to the command sent.
Throws:
FTPException
ConnectionException

getRemoteAddress

public InetAddress getRemoteAddress()
Description copied from interface: FTPClient
Returns the Address of the remote host.

Specified by:
getRemoteAddress in interface FTPClient
Returns:
InetAddress of the remote host.

getRemoteHost

public String getRemoteHost()
Description copied from interface: FTPClient
Returns the fully qaulified domain name of the remote host.

Specified by:
getRemoteHost in interface FTPClient
Returns:
domain name or IP address of the remote host.

getRemoteIPAddress

public String getRemoteIPAddress()
Description copied from interface: FTPClient
Returns the IP address of the remote host in xxx.xxx.xxx.xxx format.

Specified by:
getRemoteIPAddress in interface FTPClient
Returns:
IP address of the remote host.

getRemotePort

public int getRemotePort()
Description copied from interface: FTPClient
Returns the remote port number to which the ControlConnection is established.

Specified by:
getRemotePort in interface FTPClient
Returns:
port number.

getLocalAddress

public InetAddress getLocalAddress()
Description copied from interface: FTPClient
Returns the InetAddress of the local host.

Specified by:
getLocalAddress in interface FTPClient
Returns:
InetAddress of the local host.

getLocalHost

public String getLocalHost()
Description copied from interface: FTPClient
Returns the host name or IP address of the local host.

Specified by:
getLocalHost in interface FTPClient
Returns:
Host name or IP address of the local host.

getLocalIPAddress

public String getLocalIPAddress()
Description copied from interface: FTPClient
Returns the IP address of the local host in xxx.xxx.xxx.xxx format.

Specified by:
getLocalIPAddress in interface FTPClient
Returns:
IP address of the local host.

getLocalPort

public int getLocalPort()
Description copied from interface: FTPClient
Returns the local port number used by the control connection.

Specified by:
getLocalPort in interface FTPClient
Returns:
Local port number.

list

public RemoteFile[] list()
                  throws FTPException,
                         ParseException,
                         ConnectionException
Description copied from interface: FTPClient
Retrieves the contents (children) of the current working directory.

Specified by:
list in interface FTPClient
Returns:
Direct children of the current working directory.
Throws:
FTPException
ParseException
ConnectionException

list

public RemoteFile[] list(Filter filter)
                  throws FTPException,
                         ParseException,
                         ConnectionException
Description copied from interface: FTPClient
Retrieves the children of the current working directory. The contents will be filtered using the given filter.

Specified by:
list in interface FTPClient
Parameters:
filter - the filter to use.
Returns:
direct children of the working directory.
Throws:
FTPException
ParseException
ConnectionException

list

public RemoteFile[] list(RemoteFile dir)
                  throws FTPException,
                         ParseException,
                         ConnectionException
Description copied from interface: FTPClient
Returns the direct children of the specified directory.

Specified by:
list in interface FTPClient
Parameters:
dir - directory whose children are to be retrieved
Returns:
Direct children of the specified directory dir.
Throws:
FTPException
ParseException
ConnectionException

list

public RemoteFile[] list(RemoteFile dir,
                         Filter filter)
                  throws FTPException,
                         ParseException,
                         ConnectionException
Description copied from interface: FTPClient
Returns the direct children of the specified directory.

Specified by:
list in interface FTPClient
Parameters:
dir - directory whose children are to be retrieved.
filter - Fiter to apply.
Returns:
Direct children of the given directory.
Throws:
FTPException
ParseException
ConnectionException

createFile

public void createFile(RemoteFile file)
                throws FTPException,
                       ConnectionException
Description copied from interface: FTPClient
Creates an empty file with the given name on the remote host.

Specified by:
createFile in interface FTPClient
Parameters:
file - Path and name of the file.
Throws:
FTPException
ConnectionException

download

public void download(RemoteFile source,
                     File destination,
                     int type,
                     boolean append)
              throws FTPException,
                     ConnectionException
Description copied from interface: FTPClient
Copies the contents of the source to the local file destination.

Specified by:
download in interface FTPClient
Parameters:
source - Remote file to be copied or downloaded.
destination - Local file to which the contents are to be copied.
type - Data representation type to use for data transfer.
append - Whether or not to open the destination file in append mode.
Throws:
FTPException
ConnectionException

upload

public void upload(File source,
                   RemoteFile destination,
                   int type,
                   boolean append,
                   long skip)
            throws FTPException,
                   ConnectionException
Description copied from interface: FTPClient
copies the contents of local file source to the specified remote file destination.

Specified by:
upload in interface FTPClient
Parameters:
source - Local file to be copied.
destination - Destination file on the remote system.
type - Data representation type to use for data transfer.
append - Whether or not the destination file is to be appended with the contents of source file.
skip - Number of bytes to skip.
Throws:
FTPException
ConnectionException

addControlConnectionListener

public void addControlConnectionListener(ControlConnectionListener l)
Description copied from interface: FTPClient
Adds a listener that will be notified about the activities of ControlConnection associated with this FTPClient .

Specified by:
addControlConnectionListener in interface FTPClient
Parameters:
l - Listener to register.

removeControlConnectionListener

public void removeControlConnectionListener(ControlConnectionListener l)
Description copied from interface: FTPClient
Removes the given listener from the list of registered listenerrs.

Specified by:
removeControlConnectionListener in interface FTPClient
Parameters:
l - Listner to remove from the registered listener list.

addDataConnectionListener

public void addDataConnectionListener(DataConnectionListener l)
Description copied from interface: FTPClient
Adds a DataConnection Listener to this FTPClient.

Specified by:
addDataConnectionListener in interface FTPClient
Parameters:
l - Listener to register.

removeDataConnectionListener

public void removeDataConnectionListener(DataConnectionListener l)
Description copied from interface: FTPClient
Removes the given data connection listener from the registered list of listeners.

Specified by:
removeDataConnectionListener in interface FTPClient
Parameters:
l - Listener to unregister.

getListenerList

public EventListenerList getListenerList()
Description copied from interface: FTPClient
Returns the list of registered listeners.

Specified by:
getListenerList in interface FTPClient
Returns:
List of registered listeners.

addFTPConnectionListener

public void addFTPConnectionListener(FTPConnectionListener l)
Description copied from interface: FTPClient
Adds the given FTPConnectionListener to the list of registered listeners.

Specified by:
addFTPConnectionListener in interface FTPClient
Parameters:
l - Listener to register.

removeFTPConnectionListener

public void removeFTPConnectionListener(FTPConnectionListener l)
Description copied from interface: FTPClient
Unregisters the given listener from the list of listeners.

Specified by:
removeFTPConnectionListener in interface FTPClient
Parameters:
l - Listener to unregister.

setPassiveIPSubstitutionEnabled

public void setPassiveIPSubstitutionEnabled(boolean enable)
Description copied from interface: FTPClient
Sets or unsets the flag that determines whether or not to ignore the response (the IP address portion) of PASV command and substitute it with the original server IP address when making a PASSIVE data connection. This method has been added to support some FTP servers that return an unreachable IP address in response to the PASV command. This method can also be used to ensure that the data connections will always be made to the same server to which you are connected.

Specified by:
setPassiveIPSubstitutionEnabled in interface FTPClient
Parameters:
enable - true to enable the IP address substitution; false to disable it.

isPassiveIPSubstitutionEnabled

public boolean isPassiveIPSubstitutionEnabled()
Description copied from interface: FTPClient
Tells whether or not the substitution of passive IP address is enabled.

Specified by:
isPassiveIPSubstitutionEnabled in interface FTPClient
Returns:
true, if the addressed retunred by the server in response to a PASV command will be ignored and substituted with the original server's IP address; false, otherewise.

setProxy

public void setProxy(Proxy proxy)
Description copied from interface: FTPClient
Sets the proxy server to use when making the control/data connections.

Specified by:
setProxy in interface FTPClient
Parameters:
proxy - the proxy server to use when making the control/data connections. Supported proxy types are - SOCKS and DIRECT.

getProxy

public Proxy getProxy()
Description copied from interface: FTPClient
Returns the current proxy configuration, if any.

Specified by:
getProxy in interface FTPClient
Returns:
the current proxy configuration, if any. Returns null, if there is no proxy set.

fireConnectionOpened

protected void fireConnectionOpened(FTPConnectionEvent evt)
Fires the ConnectionOpened event to all registered listeners.

Parameters:
evt - connection opened event.

fireConnectionClosed

protected void fireConnectionClosed(FTPConnectionEvent evt)
Fires the connection closed event to all registered listeners.

Parameters:
evt - connection closed event.


Copyright © 2000-2012 jMethods, Inc.. All Rights Reserved.