edtFTPj

com.enterprisedt.net.ftp
Class FTPClient

java.lang.Object
  extended by com.enterprisedt.net.ftp.FTPClient
All Implemented Interfaces:
FTPClientInterface

public class FTPClient
extends Object
implements FTPClientInterface

Supports client-side FTP. Most common FTP operations are present in this class.

Version:
$Revision: 1.80 $
Author:
Bruce Blackshaw

Field Summary
static byte CARRIAGE_RETURN
          Used for ASCII translation
protected  FTPControlSocket control
          Socket responsible for controlling the connection
protected  String controlEncoding
          Encoding used on control socket
protected  int controlPort
          Control port number.
static String cvsId
          Revision control id
protected  FTPDataSocket data
          Socket responsible for transferring the data
static int DEFAULT_BUFFER_SIZE
          Default transfer buffer size
static String DEFAULT_ENCODING
          Default encoding used for control data
static int DEFAULT_MONITOR_INTERVAL
          Default byte interval for transfer monitor
protected  boolean detectTransferMode
          If true, filetypes are autodetected and transfer mode changed to binary/ASCII as required
protected  DirectoryEmptyStrings dirEmptyStrings
          Matcher for directory empty
protected  FileNotFoundStrings fileNotFoundStrings
          Matcher for permission denied
protected  String id
          Id of instance
protected  FTPReply lastValidReply
          Holds the last valid reply from the server on the control socket
static byte LINE_FEED
          Used for ASCII translation
protected  FTPMessageListener messageListener
          Message listener
protected  FTPProgressMonitor monitor
          Progress monitor
protected  long monitorInterval
          Bytes transferred in between monitor callbacks
protected  InetAddress remoteAddr
          Address of the remote server.
protected  String remoteHost
          Name/IP of remote host
protected  int serverWakeupInterval
          Interval in seconds in between server wakeups.
protected  int timeout
          Socket timeout for both data and control.
protected  int transferBufferSize
          Size of transfer buffers
protected  TransferCompleteStrings transferCompleteStrings
          Matcher for transfer complete
protected  FTPTransferType transferType
          Record of the transfer type - make the default ASCII
 
Constructor Summary
FTPClient()
          Default constructor should now always be used together with setter methods in preference to other constructors (now deprecated).
FTPClient(InetAddress remoteAddr)
          Deprecated. use setter methods to set properties
FTPClient(InetAddress remoteAddr, int controlPort)
          Deprecated. use setter methods to set properties
FTPClient(InetAddress remoteAddr, int controlPort, int timeout)
          Deprecated. use setter methods to set properties
FTPClient(InetAddress remoteAddr, int controlPort, int timeout, String encoding)
          Deprecated. use setter methods to set properties
FTPClient(String remoteHost)
          Deprecated. use setter methods to set properties
FTPClient(String remoteHost, int controlPort)
          Deprecated. use setter methods to set properties
FTPClient(String remoteHost, int controlPort, int timeout)
          Deprecated. use setter methods to set properties
FTPClient(String remoteHost, int controlPort, int timeout, String encoding)
          Deprecated. use setter methods to set properties
 
Method Summary
protected  void abort()
          Abort the current action
 void account(String accountInfo)
          Supply account information string to the server.
 void cancelResume()
          Cancel the resume.
 void cancelTransfer()
          Cancels the current transfer.
 void cdup()
          Change the remote working directory to the parent directory
 void chdir(String dir)
          Change the remote working directory to that supplied
protected  void checkConnection(boolean shouldBeConnected)
          Checks if the client has connected to the server and throws an exception if it hasn't.
protected  void chooseTransferMode(String filename)
          Switch the transfer mode if requested and if necessary
static void clearSOCKS()
          Clear SOCKS settings.
protected  void closeDataSocket(InputStream stream)
          Close stream for data socket.
protected  void closeDataSocket(OutputStream stream)
          Close stream for data socket
 void connect()
          Connects to the server at the address and port number defined in the constructor.
 boolean connected()
          Is this client connected?
 void debugResponses(boolean on)
          Deprecated. use the Logger class to switch debugging on and off
 void delete(String remoteFile)
          Delete the specified remote file
 String[] dir()
          List current directory's contents as an array of strings of filenames.
 String[] dir(String dirname)
          List a directory's contents as an array of strings of filenames.
 String[] dir(String dirname, boolean full)
          List a directory's contents as an array of strings.
 FTPFile[] dirDetails(String dirname)
          List a directory's contents as an array of FTPFile objects.
 boolean exists(String remoteFile)
          Does the named file exist in the current server directory?
 String[] features()
          Get the server supplied features
 FTPFile fileDetails(String name)
          Uses the MLST command to find out details about the named file.
protected  void forceResumeOff()
          Force the resume flag off.
 void get(OutputStream destStream, String remoteFile)
          Get data from the FTP server.
 byte[] get(String remoteFile)
          Get data from the FTP server.
 void get(String localPath, String remoteFile)
          Get data from the FTP server.
static String getBuildTimestamp()
          Get the build timestamp
 FTPConnectMode getConnectMode()
           
 String getControlEncoding()
          Get the encoding used for the control connection
 int getControlPort()
          Deprecated. Use FTPClientInterface.getRemotePort() instead.
 boolean getDetectTransferMode()
          Get the detect transfer mode
 String getId()
          Get the identifying string for this instance
 FTPReply getLastValidReply()
          Gets the latest valid reply from the server
 FTPMessageListener getMessageListener()
           
 long getMonitorInterval()
          Get the bytes transferred between each callback on the progress monitor
 FTPProgressMonitor getProgressMonitor()
          Get the reference to the progress monitor
 InetAddress getRemoteAddr()
           
 String getRemoteHost()
          Returns the IP address or name of the remote host.
 int getRemotePort()
          Returns the control-port being connected to on the remote server.
 int getServerWakeupInterval()
          Get server wakeup interval in seconds.
 int getTimeout()
          Get the TCP timeout
 int getTransferBufferSize()
          Get the size of the buffers used in writing to and reading from the data sockets
 FTPTransferType getType()
          Get the current transfer type
static int[] getVersion()
          Get the version of edtFTPj
 String help(String command)
          Get the help text for the specified command
protected  void initGet(String remoteFile)
          Request to the server that the get is set up
protected  void initialize(FTPControlSocket control)
          Set the control socket explicitly
protected  String initPut(String remoteFile, boolean append)
          Request the server to set up the put
static void initSOCKS(String port, String host)
          Set up SOCKS v4/v5 proxy settings.
static void initSOCKSAuthentication(String username, String password)
          Set up SOCKS username and password for SOCKS username/password authentication.
 boolean isAutoPassiveIPSubstitution()
          Is automatic substitution of the remote host IP set to be on for passive mode connections?
 boolean isDeleteOnFailure()
          If true, delete partially written files when exceptions are thrown during a download
 boolean isStrictReturnCodes()
          Determine if strict checking of return codes is switched on.
 boolean isTransferCancelled()
          Has the current transfer been cancelled?
 void keepAlive()
          Tries to keep the current connection alive by sending an innocuous commmand to signal that the client is still active
 String list(String dirname)
          Deprecated. As of FTP 1.1, replaced by dir(String)
 String list(String dirname, boolean full)
          Deprecated. As of FTP 1.1, replaced by dir(String,boolean)
 void login(String user, String password)
          Login into an account on the FTP server.
 void login(String user, String password, String accountInfo)
          Login into an account on the FTP server.
 void mkdir(String dir)
          Create the specified remote working directory
 Date modtime(String remoteFile)
          Get modification time for a remote file.
 void noOperation()
          Send a "no operation" message that does nothing.
 void password(String password)
          Supplies the password for a previously supplied username to log into the FTP server.
 String put(byte[] bytes, String remoteFile)
          Put data onto the FTP server.
 String put(byte[] bytes, String remoteFile, boolean append)
          Put data onto the FTP server.
 String put(InputStream srcStream, String remoteFile)
          Put a stream of data onto the FTP server.
 String put(InputStream srcStream, String remoteFile, boolean append)
          Put a stream of data onto the FTP server.
 String put(String localPath, String remoteFile)
          Put a local file onto the FTP server.
 String put(String localPath, String remoteFile, boolean append)
          Put a local file onto the FTP server.
 String pwd()
          Get the current remote working directory
 void quit()
          Quit the FTP session
 void quitImmediately()
          Quit the FTP session immediately.
 String quote(String command, String[] validCodes)
          Issue arbitrary ftp commands to the FTP server.
protected  int readChar(LineNumberReader in)
          Attempts to read a single character from the given InputStream.
 int readChunk(BufferedInputStream in, byte[] chunk, int chunksize)
          Attempts to read a specified number of bytes from the given InputStream and place it in the given byte-array.
protected  String readLine(LineNumberReader in)
          Attempts to read a single line from the given InputStream.
 void rename(String from, String to)
          Rename a file or directory
 void resetTransferMode(FTPTransferType previousType)
          Reset the transfer mode back to what it should be, if it has changed.
 void restart(long size)
          Issue the RESTart command to the remote server.
 void resume()
          Make the next file transfer (put or get) resume.
 void rmdir(String dir)
          Delete the specified remote working directory
 void sendServerWakeup()
          Wake up the server during a transfer to prevent a timeout from occuring.
 void setActiveIPAddress(String forcedActiveIP)
          We can force PORT to send a fixed IP address, which can be useful with certain NAT configurations.
 void setActivePortRange(int lowest, int highest)
          Force a certain range of ports to be used in active mode.
 void setAutoPassiveIPSubstitution(boolean autoPassiveIPSubstitution)
          Set automatic substitution of the remote host IP on if in passive mode
 void setConnectMode(FTPConnectMode mode)
          Set the connect mode
 void setControlEncoding(String controlEncoding)
          Set the control socket's encoding.
 void setControlPort(int controlPort)
          Deprecated. Use FTPClientInterface.setRemotePort(int) instead.
 void setDeleteOnFailure(boolean deleteOnFailure)
          Switch on or off the automatic deletion of partially written files that are left when an exception is thrown during a download
 void setDetectTransferMode(boolean detectTransferMode)
          Set autodetect of filetypes on or off.
 void setFTPFileFactory(FTPFileFactory fileFactory)
          Override the chosen file factory with a user created one - meaning that a specific parser has been selected
 void setId(String id)
          Set the identifying string for this instance
 void setMessageListener(FTPMessageListener listener)
          Set a listener that handles all FTP messages
 void setParserLocale(Locale locale)
          Set the locale for date parsing of dir listings
 void setPORTIP(String IPAddress)
          Deprecated.  
 void setProgressMonitor(FTPProgressMonitor monitor)
          Set a progress monitor for callbacks.
 void setProgressMonitor(FTPProgressMonitor monitor, long interval)
          Set a progress monitor for callbacks.
 void setRemoteAddr(InetAddress remoteAddr)
          Set the remote address
 void setRemoteHost(String remoteHost)
          Set the IP address or name of the remote host This may only be done if the client is not already connected to the server.
 void setRemotePort(int remotePort)
          Set the control to connect to on the remote server.
 void setServerWakeupInterval(int interval)
          Set server wakeup interval in seconds.
 void setStrictReturnCodes(boolean strict)
          Set strict checking of FTP return codes.
 void setTimeout(int millis)
          Set the SO_TIMEOUT in milliseconds on the underlying socket.
 void setTransferBufferSize(int size)
          Set the size of the buffers used in writing to and reading from the data sockets
 void setType(FTPTransferType type)
          Set the transfer type
protected  void setupDataSocket()
          Set up the data socket
 boolean site(String command)
          Run a site-specific command on the server.
 long size(String remoteFile)
          Get the size of a remote file.
 String stat()
          Sends stat message to enquire about the status of a transfer.
 String system()
          Get the type of the OS at the server
 String toString()
          String representation
 void user(String user)
          Supply the user name to log into an account on the FTP server.
 void validateTransfer()
          Validate that the put() or get() was successful.
protected  void validateTransferOnError(IOException ex)
          Validate a transfer when an error has occurred on the data channel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

cvsId

public static String cvsId
Revision control id


DEFAULT_MONITOR_INTERVAL

public static final int DEFAULT_MONITOR_INTERVAL
Default byte interval for transfer monitor

See Also:
Constant Field Values

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
Default transfer buffer size

See Also:
Constant Field Values

DEFAULT_ENCODING

public static final String DEFAULT_ENCODING
Default encoding used for control data

See Also:
Constant Field Values

CARRIAGE_RETURN

public static final byte CARRIAGE_RETURN
Used for ASCII translation

See Also:
Constant Field Values

LINE_FEED

public static final byte LINE_FEED
Used for ASCII translation

See Also:
Constant Field Values

control

protected FTPControlSocket control
Socket responsible for controlling the connection


data

protected FTPDataSocket data
Socket responsible for transferring the data


timeout

protected int timeout
Socket timeout for both data and control. In milliseconds


serverWakeupInterval

protected int serverWakeupInterval
Interval in seconds in between server wakeups. O is not enabled


remoteAddr

protected InetAddress remoteAddr
Address of the remote server.


remoteHost

protected String remoteHost
Name/IP of remote host


id

protected String id
Id of instance


controlPort

protected int controlPort
Control port number.


controlEncoding

protected String controlEncoding
Encoding used on control socket


dirEmptyStrings

protected DirectoryEmptyStrings dirEmptyStrings
Matcher for directory empty


transferCompleteStrings

protected TransferCompleteStrings transferCompleteStrings
Matcher for transfer complete


fileNotFoundStrings

protected FileNotFoundStrings fileNotFoundStrings
Matcher for permission denied


detectTransferMode

protected boolean detectTransferMode
If true, filetypes are autodetected and transfer mode changed to binary/ASCII as required


monitorInterval

protected long monitorInterval
Bytes transferred in between monitor callbacks


transferBufferSize

protected int transferBufferSize
Size of transfer buffers


monitor

protected FTPProgressMonitor monitor
Progress monitor


messageListener

protected FTPMessageListener messageListener
Message listener


transferType

protected FTPTransferType transferType
Record of the transfer type - make the default ASCII


lastValidReply

protected FTPReply lastValidReply
Holds the last valid reply from the server on the control socket

Constructor Detail

FTPClient

public FTPClient(String remoteHost)
          throws IOException,
                 FTPException
Deprecated. use setter methods to set properties

Constructor. Creates the control socket

Parameters:
remoteHost - the remote hostname
Throws:
IOException
FTPException

FTPClient

public FTPClient(String remoteHost,
                 int controlPort)
          throws IOException,
                 FTPException
Deprecated. use setter methods to set properties

Constructor. Creates the control socket

Parameters:
remoteHost - the remote hostname
controlPort - port for control stream (-1 for default port)
Throws:
IOException
FTPException

FTPClient

public FTPClient(String remoteHost,
                 int controlPort,
                 int timeout)
          throws IOException,
                 FTPException
Deprecated. use setter methods to set properties

Constructor. Creates the control socket

Parameters:
remoteHost - the remote hostname
controlPort - port for control stream (use -1 for the default port)
timeout - the length of the timeout, in milliseconds (pass in 0 for no timeout)
Throws:
IOException
FTPException

FTPClient

public FTPClient(String remoteHost,
                 int controlPort,
                 int timeout,
                 String encoding)
          throws IOException,
                 FTPException
Deprecated. use setter methods to set properties

Constructor. Creates the control socket

Parameters:
remoteHost - the remote hostname
controlPort - port for control stream (use -1 for the default port)
timeout - the length of the timeout, in milliseconds (pass in 0 for no timeout)
encoding - character encoding used for data
Throws:
IOException
FTPException

FTPClient

public FTPClient(InetAddress remoteAddr)
          throws IOException,
                 FTPException
Deprecated. use setter methods to set properties

Constructor. Creates the control socket

Parameters:
remoteAddr - the address of the remote host
Throws:
IOException
FTPException

FTPClient

public FTPClient(InetAddress remoteAddr,
                 int controlPort)
          throws IOException,
                 FTPException
Deprecated. use setter methods to set properties

Constructor. Creates the control socket. Allows setting of control port (normally set by default to 21).

Parameters:
remoteAddr - the address of the remote host
controlPort - port for control stream
Throws:
IOException
FTPException

FTPClient

public FTPClient(InetAddress remoteAddr,
                 int controlPort,
                 int timeout)
          throws IOException,
                 FTPException
Deprecated. use setter methods to set properties

Constructor. Creates the control socket. Allows setting of control port (normally set by default to 21).

Parameters:
remoteAddr - the address of the remote host
controlPort - port for control stream (-1 for default port)
timeout - the length of the timeout, in milliseconds (pass in 0 for no timeout)
Throws:
IOException
FTPException

FTPClient

public FTPClient(InetAddress remoteAddr,
                 int controlPort,
                 int timeout,
                 String encoding)
          throws IOException,
                 FTPException
Deprecated. use setter methods to set properties

Constructor. Creates the control socket. Allows setting of control port (normally set by default to 21).

Parameters:
remoteAddr - the address of the remote host
controlPort - port for control stream (-1 for default port)
timeout - the length of the timeout, in milliseconds (pass in 0 for no timeout)
encoding - character encoding used for data
Throws:
IOException
FTPException

FTPClient

public FTPClient()
Default constructor should now always be used together with setter methods in preference to other constructors (now deprecated). The connect() method is used to perform the actual connection to the remote host - but only for this constructor. Deprecated constructors connect in the constructor and connect() is not required (and cannot be called).

Method Detail

getVersion

public static int[] getVersion()
Get the version of edtFTPj

Returns:
int array of {major,middle,minor} version numbers

getBuildTimestamp

public static String getBuildTimestamp()
Get the build timestamp

Returns:
d-MMM-yyyy HH:mm:ss z build timestamp

connect

public void connect()
             throws IOException,
                    FTPException
Connects to the server at the address and port number defined in the constructor. Must be performed before login() or user() is called.

Specified by:
connect in interface FTPClientInterface
Throws:
IOException - Thrown if there is a TCP/IP-related error.
FTPException - Thrown if there is an error related to the FTP protocol.

connected

public boolean connected()
Is this client connected?

Specified by:
connected in interface FTPClientInterface
Returns:
true if connected, false otherwise

checkConnection

protected void checkConnection(boolean shouldBeConnected)
                        throws FTPException
Checks if the client has connected to the server and throws an exception if it hasn't. This is only intended to be used by subclasses

Throws:
FTPException - Thrown if the client has not connected to the server.

initialize

protected void initialize(FTPControlSocket control)
                   throws IOException
Set the control socket explicitly

Parameters:
control - control socket reference
Throws:
IOException

debugResponses

public void debugResponses(boolean on)
Deprecated. use the Logger class to switch debugging on and off

Switch debug of responses on or off

Parameters:
on - true if you wish to have responses to the log stream, false otherwise

getId

public String getId()
Get the identifying string for this instance

Specified by:
getId in interface FTPClientInterface
Returns:
identifying string

setId

public void setId(String id)
Set the identifying string for this instance

Specified by:
setId in interface FTPClientInterface
Parameters:
id - identifying string

setStrictReturnCodes

public void setStrictReturnCodes(boolean strict)
Set strict checking of FTP return codes. If strict checking is on (the default) code must exactly match the expected code. If strict checking is off, only the first digit must match.

Parameters:
strict - true for strict checking, false for loose checking

isStrictReturnCodes

public boolean isStrictReturnCodes()
Determine if strict checking of return codes is switched on. If it is (the default), all return codes must exactly match the expected code. If strict checking is off, only the first digit must match.

Returns:
true if strict return code checking, false if non-strict.

setDetectTransferMode

public void setDetectTransferMode(boolean detectTransferMode)
Description copied from interface: FTPClientInterface
Set autodetect of filetypes on or off. If on, the transfer mode is switched from ASCII to binary and vice versa depending on the extension of the file. After the transfer, the mode is always returned to what it was before the transfer was performed. The default is off. If the filetype is unknown, the transfer mode is unchanged

Specified by:
setDetectTransferMode in interface FTPClientInterface
Parameters:
detectTransferMode - true if detecting transfer mode, false if not

getDetectTransferMode

public boolean getDetectTransferMode()
Description copied from interface: FTPClientInterface
Get the detect transfer mode

Specified by:
getDetectTransferMode in interface FTPClientInterface
Returns:
true if we are detecting binary and ASCII transfers from the file type

chooseTransferMode

protected void chooseTransferMode(String filename)
                           throws IOException,
                                  FTPException
Switch the transfer mode if requested and if necessary

Parameters:
filename - filename of file to be transferred
Throws:
FTPException
IOException

setTimeout

public void setTimeout(int millis)
                throws IOException
Set the SO_TIMEOUT in milliseconds on the underlying socket. If set this means the socket will block in a read operation only for this length of time - useful if the FTP sever has hung, for example. The default is 0, which is an infinite timeout. Note that for JREs 1.4+, the timeout is also used when first connecting to the remote host.

Specified by:
setTimeout in interface FTPClientInterface
Parameters:
millis - The length of the timeout, in milliseconds
Throws:
IOException

getTimeout

public int getTimeout()
Get the TCP timeout

Specified by:
getTimeout in interface FTPClientInterface
Returns:
timeout that is used, in milliseconds

getRemotePort

public int getRemotePort()
Returns the control-port being connected to on the remote server. Note that this method replaces getControlPort().

Specified by:
getRemotePort in interface FTPClientInterface
Returns:
Returns the port being connected to on the remote server.

setRemotePort

public void setRemotePort(int remotePort)
                   throws FTPException
Set the control to connect to on the remote server. Can only do this if not already connected. Note that this method replaces setControlPort(int).

Specified by:
setRemotePort in interface FTPClientInterface
Parameters:
remotePort - The port to use.
Throws:
FTPException - Thrown if the client is already connected to the server.

getControlPort

public int getControlPort()
Deprecated. Use FTPClientInterface.getRemotePort() instead.

Returns the control-port being connected to on the remote server.

Returns:
Returns the port being connected to on the remote server.

setControlPort

public void setControlPort(int controlPort)
                    throws FTPException
Deprecated. Use FTPClientInterface.setRemotePort(int) instead.

Set the control to connect to on the remote server. Can only do this if not already connected.

Parameters:
controlPort - The port to use.
Throws:
FTPException - Thrown if the client is already connected to the server.

getRemoteAddr

public InetAddress getRemoteAddr()
Returns:
Returns the remoteAddr.

setRemoteAddr

public void setRemoteAddr(InetAddress remoteAddr)
                   throws FTPException
Set the remote address

Parameters:
remoteAddr - The remoteAddr to set.
Throws:
FTPException

getRemoteHost

public String getRemoteHost()
Description copied from interface: FTPClientInterface
Returns the IP address or name of the remote host.

Specified by:
getRemoteHost in interface FTPClientInterface
Returns:
Returns the remote host.

setRemoteHost

public void setRemoteHost(String remoteHost)
                   throws IOException,
                          FTPException
Description copied from interface: FTPClientInterface
Set the IP address or name of the remote host This may only be done if the client is not already connected to the server.

Specified by:
setRemoteHost in interface FTPClientInterface
Parameters:
remoteHost - The IP address or name of the remote host
Throws:
FTPException - Thrown if the client is already connected to the server.
IOException

isAutoPassiveIPSubstitution

public boolean isAutoPassiveIPSubstitution()
Is automatic substitution of the remote host IP set to be on for passive mode connections?

Returns:
true if set on, false otherwise

setAutoPassiveIPSubstitution

public void setAutoPassiveIPSubstitution(boolean autoPassiveIPSubstitution)
Set automatic substitution of the remote host IP on if in passive mode

Parameters:
autoPassiveIPSubstitution - true if set to on, false otherwise

getServerWakeupInterval

public int getServerWakeupInterval()
Get server wakeup interval in seconds. A value of 0 means it is disabled (the default).

Returns:
interval in seconds

setServerWakeupInterval

public void setServerWakeupInterval(int interval)
Set server wakeup interval in seconds. A value of 0 means it is disabled (the default). This may hang or confuse the FTP server - use with caution.

Parameters:
interval - interval in seconds

getControlEncoding

public String getControlEncoding()
Get the encoding used for the control connection

Returns:
Returns the current controlEncoding.

setControlEncoding

public void setControlEncoding(String controlEncoding)
                        throws FTPException
Set the control socket's encoding. Can only do this if not connected

Parameters:
controlEncoding - The controlEncoding to set, which is the name of a Charset
Throws:
FTPException
See Also:
Charset

getMessageListener

public FTPMessageListener getMessageListener()
Returns:
Returns the messageListener.

setMessageListener

public void setMessageListener(FTPMessageListener listener)
Set a listener that handles all FTP messages

Parameters:
listener - message listener

setConnectMode

public void setConnectMode(FTPConnectMode mode)
Set the connect mode

Parameters:
mode - ACTIVE or PASV mode

getConnectMode

public FTPConnectMode getConnectMode()
Returns:
Returns the connectMode.

setProgressMonitor

public void setProgressMonitor(FTPProgressMonitor monitor,
                               long interval)
Description copied from interface: FTPClientInterface
Set a progress monitor for callbacks. The bytes transferred in between callbacks is only indicative. In many cases, the data is read in chunks, and if the interval is set to be smaller than the chunk size, the callback will occur after after chunk transfer rather than the interval. Depending on the implementation, the chunk size can be as large as 64K.

Specified by:
setProgressMonitor in interface FTPClientInterface
Parameters:
monitor - the monitor object
interval - bytes transferred in between callbacks

setProgressMonitor

public void setProgressMonitor(FTPProgressMonitor monitor)
Description copied from interface: FTPClientInterface
Set a progress monitor for callbacks. Uses default callback interval

Specified by:
setProgressMonitor in interface FTPClientInterface
Parameters:
monitor - the monitor object

getProgressMonitor

public FTPProgressMonitor getProgressMonitor()
Get the reference to the progress monitor

Returns:
progress monitor

getMonitorInterval

public long getMonitorInterval()
Description copied from interface: FTPClientInterface
Get the bytes transferred between each callback on the progress monitor

Specified by:
getMonitorInterval in interface FTPClientInterface
Returns:
long bytes to be transferred before a callback

setTransferBufferSize

public void setTransferBufferSize(int size)
Set the size of the buffers used in writing to and reading from the data sockets

Parameters:
size - new size of buffer in bytes

getTransferBufferSize

public int getTransferBufferSize()
Get the size of the buffers used in writing to and reading from the data sockets

Returns:
transfer buffer size

cancelTransfer

public void cancelTransfer()
Description copied from interface: FTPClientInterface
Cancels the current transfer. Generally called from a separate thread. Note that this may leave partially written files on the server or on local disk, and should not be used unless absolutely necessary. After the transfer is cancelled the connection may be in an inconsistent state, therefore it is best to quit and reconnect. It may cause exceptions to be thrown depending on the underlying protocol being used. Note that this can also be used to cancel directory listings, which can involve large amounts of data for directories containing many files.

Specified by:
cancelTransfer in interface FTPClientInterface

isTransferCancelled

public boolean isTransferCancelled()
Has the current transfer been cancelled?

Returns:
true if cancel, false otherwise

isDeleteOnFailure

public boolean isDeleteOnFailure()
If true, delete partially written files when exceptions are thrown during a download

Returns:
true if delete local file on error

setDeleteOnFailure

public void setDeleteOnFailure(boolean deleteOnFailure)
Switch on or off the automatic deletion of partially written files that are left when an exception is thrown during a download

Parameters:
deleteOnFailure - true if delete when a failure occurs

setPORTIP

public void setPORTIP(String IPAddress)
               throws FTPException
Deprecated. 

We can force PORT to send a fixed IP address, which can be useful with certain NAT configurations. Must be connected to the remote host to call this method.

Parameters:
IPAddress - IP address to force, in 192.168.1.0 form
Throws:
FTPException

setActiveIPAddress

public void setActiveIPAddress(String forcedActiveIP)
                        throws FTPException
We can force PORT to send a fixed IP address, which can be useful with certain NAT configurations. Must be connected to the remote host to call this method.

Parameters:
forcedActiveIP - IP address to force, in 192.168.1.0 form or in IPV6 form, e.g. 1080::8:800:200C:417A
Throws:
FTPException

setActivePortRange

public void setActivePortRange(int lowest,
                               int highest)
                        throws FTPException
Force a certain range of ports to be used in active mode. This is generally so that a port range can be configured in a firewall. Note that if lowest == highest, a single port will be used. This works well for uploads, but downloads generally require multiple ports, as most servers fail to create a connection repeatedly for the same port.

Parameters:
lowest - Lower limit of range.
highest - Upper limit of range.
Throws:
FTPException

login

public void login(String user,
                  String password)
           throws IOException,
                  FTPException
Login into an account on the FTP server. This call completes the entire login process. Note that connect() must be called first.

Parameters:
user - user name
password - user's password
Throws:
IOException
FTPException

login

public void login(String user,
                  String password,
                  String accountInfo)
           throws IOException,
                  FTPException
Login into an account on the FTP server. This call completes the entire login process. This method permits additional account information to be supplied. FTP servers can use combinations of these parameters in many different ways, e.g. to pass in proxy details via this method, some servers use the "user" as 'ftpUser + "@" + ftpHost + " " + ftpProxyUser', the "password" as the FTP user's password, and the accountInfo as the proxy password. Note that connect() must be called first.

Parameters:
user - user name
password - user's password
accountInfo - account info string
Throws:
IOException
FTPException

user

public void user(String user)
          throws IOException,
                 FTPException
Supply the user name to log into an account on the FTP server. Must be followed by the password() method - but we allow for no password. Note that connect() must be called first.

Parameters:
user - user name
Throws:
IOException
FTPException

password

public void password(String password)
              throws IOException,
                     FTPException
Supplies the password for a previously supplied username to log into the FTP server. Must be preceeded by the user() method

Parameters:
password - The password.
Throws:
IOException
FTPException

account

public void account(String accountInfo)
             throws IOException,
                    FTPException
Supply account information string to the server. This can be used for a variety of purposes - for example, the server could indicate that a password has expired (by sending 332 in reply to PASS) and a new password automatically supplied via ACCT. It is up to the server how it uses this string.

Parameters:
accountInfo - account information string
Throws:
IOException
FTPException

initSOCKS

public static void initSOCKS(String port,
                             String host)
Set up SOCKS v4/v5 proxy settings. This can be used if there is a SOCKS proxy server in place that must be connected thru. Note that setting these properties directs all TCP sockets in this JVM to the SOCKS proxy

Parameters:
port - SOCKS proxy port
host - SOCKS proxy hostname

initSOCKSAuthentication

public static void initSOCKSAuthentication(String username,
                                           String password)
Set up SOCKS username and password for SOCKS username/password authentication. Often, no authentication will be required but the SOCKS server may be configured to request these.

Parameters:
username - the SOCKS username
password - the SOCKS password

clearSOCKS

public static void clearSOCKS()
Clear SOCKS settings. Note that setting these properties affects all TCP sockets in this JVM


quote

public String quote(String command,
                    String[] validCodes)
             throws IOException,
                    FTPException
Issue arbitrary ftp commands to the FTP server.

Parameters:
command - ftp command to be sent to server
validCodes - valid return codes for this command. If null is supplied no validation is performed
Returns:
the text returned by the FTP server
Throws:
IOException
FTPException

exists

public boolean exists(String remoteFile)
               throws IOException,
                      FTPException
Description copied from interface: FTPClientInterface
Does the named file exist in the current server directory?

Specified by:
exists in interface FTPClientInterface
Parameters:
remoteFile - name of remote file
Returns:
true if exists, false otherwise
Throws:
IOException
FTPException

size

public long size(String remoteFile)
          throws IOException,
                 FTPException
Description copied from interface: FTPClientInterface
Get the size of a remote file. This is not a standard FTP command, it is defined in "Extensions to FTP", a draft RFC (draft-ietf-ftpext-mlst-16.txt)

Specified by:
size in interface FTPClientInterface
Parameters:
remoteFile - name or path of remote file in current directory
Returns:
size of file in bytes
Throws:
IOException
FTPException

resume

public void resume()
            throws FTPException
Description copied from interface: FTPClientInterface
Make the next file transfer (put or get) resume. For puts(), the bytes already transferred are skipped over, while for gets(), if writing to a file, it is opened in append mode, and only the bytes required are transferred. Currently resume is only supported for BINARY transfers (which is generally what it is most useful for).

Specified by:
resume in interface FTPClientInterface
Throws:
FTPException

cancelResume

public void cancelResume()
                  throws IOException,
                         FTPException
Description copied from interface: FTPClientInterface
Cancel the resume. Use this method if something goes wrong and the server is left in an inconsistent state

Specified by:
cancelResume in interface FTPClientInterface
Throws:
IOException
FTPException

forceResumeOff

protected void forceResumeOff()
Force the resume flag off. Internal use only.


restart

public void restart(long size)
             throws IOException,
                    FTPException
Issue the RESTart command to the remote server. This indicates the byte position that REST is performed at. For put, bytes start at this point, while for get, bytes are fetched from this point.

Parameters:
size - the REST param, the mark at which the restart is performed on the remote file. For STOR, this is retrieved by SIZE
Throws:
IOException
FTPException

put

public String put(String localPath,
                  String remoteFile)
           throws IOException,
                  FTPException
Description copied from interface: FTPClientInterface
Put a local file onto the FTP server. It is placed in the current directory. If a remote file name is supplied, it is stored as that name on the server. If null is supplied, the server will generate a unique filename (via STOU) if it supports this option.

Specified by:
put in interface FTPClientInterface
Parameters:
localPath - path of the local file
remoteFile - name of remote file in current directory, or null if a unique filename is to be generated by the server
Returns:
The name of the remote file - normally the name supplied, or else the unique name generated by the server.
Throws:
IOException
FTPException

put

public String put(InputStream srcStream,
                  String remoteFile)
           throws IOException,
                  FTPException
Description copied from interface: FTPClientInterface
Put a stream of data onto the FTP server. It is placed in the current directory. If a remote file name is supplied, it is stored as that name on the server. If null is supplied, the server will generate a unique filename (via STOU) if it supports this option.

Specified by:
put in interface FTPClientInterface
Parameters:
srcStream - input stream of data to put
remoteFile - name of remote file in current directory, or null if a unique filename is to be generated by the server
Returns:
The name of the remote file - normally the name supplied, or else the unique name generated by the server.
Throws:
IOException
FTPException

put

public String put(String localPath,
                  String remoteFile,
                  boolean append)
           throws IOException,
                  FTPException
Description copied from interface: FTPClientInterface
Put a local file onto the FTP server. It is placed in the current directory. If a remote file name is supplied, it is stored as that name on the server. If null is supplied, the server will generate a unique filename (via STOU) if it supports this option. Allows appending if current file exists.

Specified by:
put in interface FTPClientInterface
Parameters:
localPath - path of the local file
remoteFile - name of remote file in current directory, or null if a unique filename is to be generated by the server
append - true if appending, false otherwise
Returns:
The name of the remote file - normally the name supplied, or else the unique name generated by the server.
Throws:
IOException
FTPException

put

public String put(InputStream srcStream,
                  String remoteFile,
                  boolean append)
           throws IOException,
                  FTPException
Description copied from interface: FTPClientInterface
Put a stream of data onto the FTP server. It is placed in the current directory. If a remote file name is supplied, it is stored as that name on the server. If null is supplied, the server will generate a unique filename (via STOU) if it supports this option. Allows appending if current file exists.

Specified by:
put in interface FTPClientInterface
Parameters:
srcStream - input stream of data to put
remoteFile - name of remote file in current directory, or null if a unique filename is to be generated by the server
append - true if appending, false otherwise
Returns:
The name of the remote file - normally the name supplied, or else the unique name generated by the server.
Throws:
IOException
FTPException

validateTransfer

public void validateTransfer()
                      throws IOException,
                             FTPException
Validate that the put() or get() was successful. This method is not for general use.

Throws:
IOException
FTPException

validateTransferOnError

protected void validateTransferOnError(IOException ex)
                                throws IOException,
                                       FTPException
Validate a transfer when an error has occurred on the data channel. Set a very short transfer in case things have hung. Set it back at the end.

Throws:
IOException
FTPException

closeDataSocket

protected void closeDataSocket(InputStream stream)
Close stream for data socket. Not for general use!

Parameters:
stream - stream reference

closeDataSocket

protected void closeDataSocket(OutputStream stream)
Close stream for data socket

Parameters:
stream - stream reference

setupDataSocket

protected void setupDataSocket()
                        throws IOException,
                               FTPException
Set up the data socket

Throws:
FTPException
IOException

initPut

protected String initPut(String remoteFile,
                         boolean append)
                  throws IOException,
                         FTPException
Request the server to set up the put

Parameters:
remoteFile - name of remote file in current directory
append - true if appending, false otherwise
Throws:
IOException
FTPException

put

public String put(byte[] bytes,
                  String remoteFile)
           throws IOException,
                  FTPException
Description copied from interface: FTPClientInterface
Put data onto the FTP server. It is placed in the current directory. If a remote file name is supplied, it is stored as that name on the server. If null is supplied, the server will generate a unique filename (via STOU) if it supports this option.

Specified by:
put in interface FTPClientInterface
Parameters:
bytes - array of bytes
remoteFile - name of remote file in current directory, or null if a unique filename is to be generated by the server
Returns:
The name of the remote file - normally the name supplied, or else the unique name generated by the server.
Throws:
IOException
FTPException

put

public String put(byte[] bytes,
                  String remoteFile,
                  boolean append)
           throws IOException,
                  FTPException
Description copied from interface: FTPClientInterface
Put data onto the FTP server. It is placed in the current directory. If a remote file name is supplied, it is stored as that name on the server. If null is supplied, the server will generate a unique filename (via STOU) if it supports this option. Allows appending if current file exists.

Specified by:
put in interface FTPClientInterface
Parameters:
bytes - array of bytes
remoteFile - name of remote file in current directory, or null if a unique filename is to be generated by the server
append - true if appending, false otherwise
Returns:
The name of the remote file - normally the name supplied, or else the unique name generated by the server.
Throws:
IOException
FTPException

get

public void get(String localPath,
                String remoteFile)
         throws IOException,
                FTPException
Description copied from interface: FTPClientInterface
Get data from the FTP server. Uses the currently set transfer mode.

Specified by:
get in interface FTPClientInterface
Parameters:
localPath - local file to put data in
remoteFile - name of remote file in current directory
Throws:
IOException
FTPException

get

public void get(OutputStream destStream,
                String remoteFile)
         throws IOException,
                FTPException
Description copied from interface: FTPClientInterface
Get data from the FTP server. Uses the currently set transfer mode.

Specified by:
get in interface FTPClientInterface
Parameters:
destStream - data stream to write data to
remoteFile - name of remote file in current directory
Throws:
IOException
FTPException

resetTransferMode

public void resetTransferMode(FTPTransferType previousType)
                       throws IOException,
                              FTPException
Reset the transfer mode back to what it should be, if it has changed.

Parameters:
previousType - previous transfer type
Throws:
IOException
FTPException

initGet

protected void initGet(String remoteFile)
                throws IOException,
                       FTPException
Request to the server that the get is set up

Parameters:
remoteFile - name of remote file
Throws:
IOException
FTPException

get

public byte[] get(String remoteFile)
           throws IOException,
                  FTPException
Description copied from interface: FTPClientInterface
Get data from the FTP server. Transfers in whatever mode we are in. Retrieve as a byte array. Note that we may experience memory limitations as the entire file must be held in memory at one time.

Specified by:
get in interface FTPClientInterface
Parameters:
remoteFile - name of remote file in current directory
Throws:
IOException
FTPException

site

public boolean site(String command)
             throws IOException,
                    FTPException
Run a site-specific command on the server. Support for commands is dependent on the server

Parameters:
command - the site command to run
Returns:
true if command ok, false if command not implemented
Throws:
IOException
FTPException

list

public String list(String dirname)
            throws IOException,
                   FTPException
Deprecated. As of FTP 1.1, replaced by dir(String)

List a directory's contents

Parameters:
dirname - the name of the directory (not a file mask)
Returns:
a string containing the line separated directory listing
Throws:
IOException
FTPException

list

public String list(String dirname,
                   boolean full)
            throws IOException,
                   FTPException
Deprecated. As of FTP 1.1, replaced by dir(String,boolean)

List a directory's contents as one string. A detailed listing is available, otherwise just filenames are provided. The detailed listing varies in details depending on OS and FTP server.

Parameters:
dirname - the name of the directory(not a file mask)
full - true if detailed listing required false otherwise
Returns:
a string containing the line separated directory listing
Throws:
IOException
FTPException

setFTPFileFactory

public void setFTPFileFactory(FTPFileFactory fileFactory)
Override the chosen file factory with a user created one - meaning that a specific parser has been selected

Parameters:
fileFactory -

setParserLocale

public void setParserLocale(Locale locale)
Set the locale for date parsing of dir listings

Parameters:
locale - new locale to use

fileDetails

public FTPFile fileDetails(String name)
                    throws IOException,
                           FTPException,
                           ParseException
Uses the MLST command to find out details about the named file. A single filename should be supplied. Note that the MLST command is not supported by many servers.

Parameters:
name - name of a file
Returns:
if it exists, an FTPFile object
Throws:
IOException
FTPException
ParseException

dirDetails

public FTPFile[] dirDetails(String dirname)
                     throws IOException,
                            FTPException,
                            ParseException
Description copied from interface: FTPClientInterface
List a directory's contents as an array of FTPFile objects. Should work for Windows and most Unix FTP servers - let us know about unusual formats (http://www.enterprisedt.com/forums/index.php). If accurate timestamps are required (i.e. to the second), it is generally better to use @see #modtime(String).

Specified by:
dirDetails in interface FTPClientInterface
Parameters:
dirname - name of directory (some servers permit a filemask)
Returns:
an array of FTPFile objects
Throws:
IOException
FTPException
ParseException

dir

public String[] dir()
             throws IOException,
                    FTPException
Description copied from interface: FTPClientInterface
List current directory's contents as an array of strings of filenames.

Specified by:
dir in interface FTPClientInterface
Returns:
an array of current directory listing strings
Throws:
IOException
FTPException

dir

public String[] dir(String dirname)
             throws IOException,
                    FTPException
Description copied from interface: FTPClientInterface
List a directory's contents as an array of strings of filenames.

Specified by:
dir in interface FTPClientInterface
Parameters:
dirname - name of directory OR filemask
Returns:
an array of directory listing strings
Throws:
IOException
FTPException

dir

public String[] dir(String dirname,
                    boolean full)
             throws IOException,
                    FTPException
Description copied from interface: FTPClientInterface
List a directory's contents as an array of strings. A detailed listing is available, otherwise just filenames are provided. The detailed listing varies in details depending on OS and FTP server. Note that a full listing can be used on a file name to obtain information about a file

Specified by:
dir in interface FTPClientInterface
Parameters:
dirname - name of directory OR filemask
full - true if detailed listing required false otherwise
Returns:
an array of directory listing strings
Throws:
IOException
FTPException

readChunk

public int readChunk(BufferedInputStream in,
                     byte[] chunk,
                     int chunksize)
              throws IOException
Attempts to read a specified number of bytes from the given InputStream and place it in the given byte-array. The purpose of this method is to permit subclasses to execute any additional code necessary when performing this operation.

Parameters:
in - The InputStream to read from.
chunk - The byte-array to place read bytes in.
chunksize - Number of bytes to read.
Returns:
Number of bytes actually read.
Throws:
IOException - Thrown if there was an error while reading.

readChar

protected int readChar(LineNumberReader in)
                throws IOException
Attempts to read a single character from the given InputStream. The purpose of this method is to permit subclasses to execute any additional code necessary when performing this operation.

Parameters:
in - The LineNumberReader to read from.
Returns:
The character read.
Throws:
IOException - Thrown if there was an error while reading.

readLine

protected String readLine(LineNumberReader in)
                   throws IOException
Attempts to read a single line from the given InputStream. The purpose of this method is to permit subclasses to execute any additional code necessary when performing this operation.

Parameters:
in - The LineNumberReader to read from.
Returns:
The string read.
Throws:
IOException - Thrown if there was an error while reading.

getLastValidReply

public FTPReply getLastValidReply()
Gets the latest valid reply from the server

Returns:
reply object encapsulating last valid server response

getType

public FTPTransferType getType()
Get the current transfer type

Specified by:
getType in interface FTPClientInterface
Returns:
the current type of the transfer, i.e. BINARY or ASCII

setType

public void setType(FTPTransferType type)
             throws IOException,
                    FTPException
Set the transfer type

Specified by:
setType in interface FTPClientInterface
Parameters:
type - the transfer type to set the server to
Throws:
IOException
FTPException

delete

public void delete(String remoteFile)
            throws IOException,
                   FTPException
Description copied from interface: FTPClientInterface
Delete the specified remote file

Specified by:
delete in interface FTPClientInterface
Parameters:
remoteFile - name of remote file to delete
Throws:
IOException
FTPException

rename

public void rename(String from,
                   String to)
            throws IOException,
                   FTPException
Description copied from interface: FTPClientInterface
Rename a file or directory

Specified by:
rename in interface FTPClientInterface
Parameters:
from - name of file or directory to rename
to - intended name
Throws:
IOException
FTPException

rmdir

public void rmdir(String dir)
           throws IOException,
                  FTPException
Description copied from interface: FTPClientInterface
Delete the specified remote working directory

Specified by:
rmdir in interface FTPClientInterface
Parameters:
dir - name of remote directory to delete
Throws:
IOException
FTPException

mkdir

public void mkdir(String dir)
           throws IOException,
                  FTPException
Description copied from interface: FTPClientInterface
Create the specified remote working directory

Specified by:
mkdir in interface FTPClientInterface
Parameters:
dir - name of remote directory to create
Throws:
IOException
FTPException

chdir

public void chdir(String dir)
           throws IOException,
                  FTPException
Description copied from interface: FTPClientInterface
Change the remote working directory to that supplied

Specified by:
chdir in interface FTPClientInterface
Parameters:
dir - name of remote directory to change to
Throws:
IOException
FTPException

cdup

public void cdup()
          throws IOException,
                 FTPException
Description copied from interface: FTPClientInterface
Change the remote working directory to the parent directory

Specified by:
cdup in interface FTPClientInterface
Throws:
IOException
FTPException

modtime

public Date modtime(String remoteFile)
             throws IOException,
                    FTPException
Description copied from interface: FTPClientInterface
Get modification time for a remote file. For accurate modification times (e.g. to the second) this method is to be preferred over @see #dirDetails(java.lang.String) which parses a listing returned by the server. The timezone is GMT.

Specified by:
modtime in interface FTPClientInterface
Parameters:
remoteFile - name of remote file
Returns:
modification time of file as a date
Throws:
IOException
FTPException

pwd

public String pwd()
           throws IOException,
                  FTPException
Description copied from interface: FTPClientInterface
Get the current remote working directory

Specified by:
pwd in interface FTPClientInterface
Returns:
the current working directory
Throws:
IOException
FTPException

features

public String[] features()
                  throws IOException,
                         FTPException
Get the server supplied features

Returns:
string containing server features, or null if no features or not supported
Throws:
IOException
FTPException

system

public String system()
              throws IOException,
                     FTPException
Get the type of the OS at the server

Returns:
the type of server OS
Throws:
IOException
FTPException

noOperation

public void noOperation()
                 throws IOException,
                        FTPException
Send a "no operation" message that does nothing. Can be called periodically to prevent the connection timing out

Throws:
IOException
FTPException

stat

public String stat()
            throws IOException,
                   FTPException
Sends stat message to enquire about the status of a transfer.

Throws:
IOException
FTPException

sendServerWakeup

public void sendServerWakeup()
                      throws IOException,
                             FTPException
Wake up the server during a transfer to prevent a timeout from occuring. This may hang or confuse the server - use with caution.

Throws:
IOException
FTPException

keepAlive

public void keepAlive()
               throws IOException,
                      FTPException
Tries to keep the current connection alive by sending an innocuous commmand to signal that the client is still active

Specified by:
keepAlive in interface FTPClientInterface
Throws:
IOException
FTPException

help

public String help(String command)
            throws IOException,
                   FTPException
Get the help text for the specified command

Parameters:
command - name of the command to get help on
Returns:
help text from the server for the supplied command
Throws:
IOException
FTPException

abort

protected void abort()
              throws IOException,
                     FTPException
Abort the current action

Throws:
IOException
FTPException

quit

public void quit()
          throws IOException,
                 FTPException
Description copied from interface: FTPClientInterface
Quit the FTP session

Specified by:
quit in interface FTPClientInterface
Throws:
IOException
FTPException

quitImmediately

public void quitImmediately()
                     throws IOException,
                            FTPException
Description copied from interface: FTPClientInterface
Quit the FTP session immediately. If a transfer is underway it will be terminated.

Specified by:
quitImmediately in interface FTPClientInterface
Throws:
IOException
FTPException

toString

public String toString()
String representation

Overrides:
toString in class Object

edtFTPj

Copyright © 2000-2007 Enterprise Distributed Technologies. All Rights Reserved.