Class FTPClient
- All Implemented Interfaces:
FTPClientInterface
- Version:
- $Revision$
- Author:
- Bruce Blackshaw
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byteUsed for ASCII translationprotected FTPControlSocketSocket responsible for controlling the connectionprotected StringEncoding used on control socketprotected intControl port number.static StringRevision control idprotected com.enterprisedt.net.ftp.internal.FTPDataSocketSocket responsible for transferring the dataprotected DataChannelCallbackPasv callback methodprotected intSize of data socket's receive bufferprotected intSize of data socket's send bufferstatic final intDefault transfer buffer sizestatic final StringDefault encoding used for control datastatic Locale[]Default localesstatic final intDefault byte interval for transfer monitorstatic final intDefault number of retries for file transfersstatic final intDefault retry delay in millisecondsstatic final intDefault SO_SNDBUF and SO_RCVBUF sizestatic final intDefault timeoutprotected booleanIf true, filetypes are autodetected and transfer mode changed to binary/ASCII as requiredprotected DirectoryEmptyStringsMatcher for directory emptyprotected booleanIf true, file locking is used on local downloaded files to prevent other processes corrupting themprotected FileNotFoundStringsMatcher for permission deniedstatic final byte[]Used for ASCII translationprotected StringId of instanceprotected FTPReplyHolds the last reply from the server on the control socketprotected FTPReplyHolds the last valid reply from the server on the control socketstatic final byteUsed for ASCII translationstatic byte[]Local line separatorprotected FTPMessageListenerMessage listenerprotected FTPProgressMonitorProgress monitorprotected FTPProgressMonitorExFile transfer listenerprotected longBytes transferred in between monitor callbacksprotected StringPassword cachedprotected InetAddressAddress of the remote server.protected StringName/IP of remote hostprotected intInterval in seconds in between server wakeups.protected BandwidthThrottlerThreshold for throttlingprotected intSocket timeout for both data and control.protected intSize of transfer buffersprotected TransferCompleteStringsMatcher for transfer completeprotected FTPTransferTypeRecord of the transfer type - make the default ASCIIprotected booleanNOOP supported?protected StringUsername cached -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor should now always be used together with setter methods in preference to other constructors (now deprecated).Deprecated.use setter methods to set propertiesDeprecated.use setter methods to set propertiesDeprecated.use setter methods to set propertiesDeprecated.use setter methods to set propertiesFTPClient(InetAddress remoteAddr) Deprecated.use setter methods to set propertiesFTPClient(InetAddress remoteAddr, int controlPort) Deprecated.use setter methods to set propertiesFTPClient(InetAddress remoteAddr, int controlPort, int timeout) Deprecated.use setter methods to set propertiesFTPClient(InetAddress remoteAddr, int controlPort, int timeout, String encoding) Deprecated.use setter methods to set properties -
Method Summary
Modifier and TypeMethodDescriptionprotected voidabort()Abort the current actionvoidSupply account information string to the server.voidCancel the resume.voidCancels the current transfer.voidcdup()Change the remote working directory to the parent directoryvoidChange the remote working directory to that suppliedprotected voidcheckConnection(boolean shouldBeConnected) Checks if the client has connected to the server and throws an exception if it hasn't.protected FTPTransferTypechooseTransferMode(String filename) Switch the transfer mode if requested and if necessarystatic voidClear SOCKS settings.protected voidcloseDataSocket(InputStream stream) Close stream for data socket.protected voidcloseDataSocket(OutputStream stream) Close stream for data socketprotected voidvoidconnect()Connects to the server at the address and port number defined in the constructor.booleanIs this client connected?protected voidSet up the data socketvoiddebugResponses(boolean on) Deprecated.use the Logger class to switch debugging on and offvoidDelete the specified remote fileString[]dir()List current directory's contents as an array of strings of filenames.String[]List a directory's contents as an array of strings of filenames.String[]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.voiddirDetails(String dirname, DirectoryListCallback lister) List a directory's contents via a callback.FTPFile[]dirDetailsM(String dirname) Uses the MLSD command to find out details about the named directory.executeCommand(String command) Request that the remote server execute the literal command supplied.booleanDeprecated.Use existsFile(String).booleanexistsDirectory(String remoteDirectory) Use to find out if a directory exists or not.booleanexistsFile(String remoteFile) Use to find out if a file exists or not.String[]features()Get the server supplied featuresfileDetails(String name) Uses the MLST command to find out details about the named file.protected voidForce the resume flag off.voidget(OutputStream destStream, String remoteFile) Get data from the FTP server.byte[]Get data from the FTP server.voidGet data from the FTP server.intGet the upper limit of the port range for active mode.Get the active IP address that is set.intGet the lower limit of the port range for active mode.static StringGet the build timestampGet the encoding used for the control connectionintDeprecated.UseFTPClientInterface.getRemotePort()instead.intDeprecated.intDeprecated.intGet the number of files deleted since the count was resetbooleanGet the detect transfer modeGet class that holds fragments of server messages that indicate a directory is empty.intGet the number of files downloaded since the count was resetbooleanDetermine if file locking on local downloaded files is being used or not.Get class that holds fragments of server messages that indicate a file was not found.getId()Get the identifying string for this instanceprotected InputStreamGet the data input stream.Gets the last reply from the server, whether valid or notGets the latest valid reply from the serverbooleanAre we listening on all interfaces in active mode, which is the default?longGet the bytes transferred between each callback on the progress monitorintGet the size of the network buffers (SO_SNDBUF and SO_RCVBUF).protected OutputStreamGet the data input stream.Get the reference to the progress monitorGet reference to the transfer listenerReturns the IP address or name of the remote host.intReturns the control-port being connected to on the remote server.intGet the retry count for retrying file transfers.intGet the retry delay between retry attempts, in milliseconds.intGet server wakeup interval in seconds.intGet the TCP timeoutintGet the size of the buffers used in writing to and reading from the data socketsGet class that holds fragments of server messages that indicate a transfer completed.getType()Get the current transfer typeintGet the number of files uploaded since the count was resetstatic int[]Get the version of edtFTPjGet the help text for the specified commandprotected voidRequest to the server that the get is set upprotected voidinitialize(FTPControlSocket control) Set the control socket explicitlyprotected StringRequest the server to set up the putstatic voidSet up SOCKS v4/v5 proxy settings.static voidinitSOCKSAuthentication(String username, String password) Set up SOCKS username and password for SOCKS username/password authentication.booleanIs automatic substitution of the remote host IP set to be on for passive mode connections?booleanIf true, delete partially written files when exceptions are thrown during a downloadbooleanDetermine if strict checking of return codes is switched on.booleanHas the current transfer been cancelled?voidTries to keep the current connection alive by sending an innocuous command to signal that the client is still activeDeprecated.As of FTP 1.1, replaced bydir(String)Deprecated.As of FTP 1.1, replaced bydir(String,boolean)voidLogin into an account on the FTP server.voidLogin into an account on the FTP server.voidCreate the specified remote working directoryGet modification time for a remote file.voidnoOp()Send the NOOP messagevoidSend a "no operation" message that does nothing.voidSupplies the password for a previously supplied username to log into the FTP server.protected voidpostTransferChecks(byte[] localBytes, String remotePath, FTPTransferType transferType, boolean append) Can be overridden by subclasses to do any necessary post transfer checking.protected voidpostTransferChecks(String localPath, String remotePath, FTPTransferType transferType, boolean append) Can be overridden by subclasses to do any necessary post transfer checking.Put data onto the FTP server.Put data onto the FTP server.put(InputStream srcStream, String remoteFile) Put a stream of data onto the FTP server.put(InputStream srcStream, String remoteFile, boolean append) Put a stream of data onto the FTP server.Put a local file onto the FTP server.Put a local file onto the FTP server.pwd()Get the current remote working directoryvoidquit()Quit the FTP sessionvoidQuit the FTP session immediately.Issue arbitrary ftp commands to the FTP server.Issue arbitrary ftp commands to the FTP server.protected intAttempts to read a single character from the givenInputStream.intreadChunk(BufferedInputStream in, byte[] chunk, int chunksize) Attempts to read a specified number of bytes from the givenInputStreamand place it in the given byte-array.intreadChunk(BufferedInputStream in, byte[] chunk, int offset, int chunksize) Attempts to read a specified number of bytes from the givenInputStreamand place it in the given byte-array.protected StringAttempts to read a single line from the givenInputStream.protected voidReconnect to the servervoidRename a file or directoryvoidReset the count of deleted files to zero.voidReset the count of downloaded files to zero.voidresetTransferMode(FTPTransferType previousType) Reset the transfer mode back to what it should be, if it has changed.voidReset the count of uploaded files to zero.voidrestart(long size) Issue the RESTart command to the remote server.voidresume()Make the next file transfer (put or get) resume.voidresumeNextDownload(long offset) Make the next download resume at a specific point.voidDelete the specified remote working directorysendCommand(String command) Send a command to the server and get the replyvoidWake up the server during a transfer to prevent a timeout from occuring.voidsetActiveIPAddress(String activeIP) We can force PORT to send a fixed IP address, which can be useful with certain NAT configurations.voidsetActivePortRange(int lowest, int highest) Force a certain range of ports to be used in active mode.voidsetAutoPassiveIPSubstitution(boolean autoPassiveIPSubstitution) Set automatic substitution of the remote host IP on if in passive mode.voidsetConnectMode(FTPConnectMode mode) Set the connect modevoidsetControlEncoding(String controlEncoding) Set the control socket's encoding.voidsetControlPort(int controlPort) Deprecated.UseFTPClientInterface.setRemotePort(int)instead.voidsetDataChannelCallback(DataChannelCallback callback) Set the data channel callback, which notifies of the ip and port number to be connected to, and gives an opportunity to modify these valuesvoidsetDataReceiveBufferSize(int size) Deprecated.voidsetDataSendBufferSize(int size) Deprecated.voidsetDeleteOnFailure(boolean deleteOnFailure) Switch on or off the automatic deletion of partially written files that are left when an exception is thrown during a downloadvoidsetDetectTransferMode(boolean detectTransferMode) Set autodetect of filetypes on or off.voidsetDirectoryEmptyMessages(DirectoryEmptyStrings dirEmptyStrings) Set a new instance of the strings classvoidsetFileLockingEnabled(boolean lockingEnabled) Set file locking to enabled or disabled.voidsetFileNotFoundMessages(FileNotFoundStrings fileNotFoundStrings) Set a new instance of the strings classvoidsetForceUniqueNames(boolean forceUnique) Set to true if the STOU command is always to be used when uploading files, even if a filename is supplied.voidsetFTPFileFactory(FTPFileFactory fileFactory) Override the chosen file factory with a user created one - meaning that a specific parser has been selectedvoidSet the identifying string for this instancevoidsetListenOnAllInterfaces(boolean listenOnAll) Listen on all interfaces for active mode transfers (the default).voidsetMessageListener(FTPMessageListener listener) Set a listener that handles all FTP messagesvoidsetModTime(String remoteFile, Date modTime) Set the last modified time (UTC) for the supplied file.voidsetMonitorInterval(long interval) Set the number of bytes transferred between each callback on the progress monitor param interval bytes to be transferred before a callbackvoidsetNetworkBufferSize(int networkBufferSize) Set the size of the network buffers (SO_SNDBUF and SO_RCVBUF).voidsetParserLocale(Locale locale) Deprecated.@see FTPClient#setParserLocales(Locale[])voidsetParserLocales(Locale[] locales) Set the list of locales to be tried for date parsing of dir listingsvoidDeprecated.voidsetProgressMonitor(FTPProgressMonitor monitor) Set a progress monitor for callbacks.voidsetProgressMonitor(FTPProgressMonitor monitor, long interval) Set a progress monitor for callbacks.voidsetProgressMonitorEx(FTPProgressMonitorEx monitorEx) Set reference to the transfer listenervoidsetRemoteAddr(InetAddress remoteAddr) Set the remote addressvoidsetRemoteHost(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.voidsetRemotePort(int remotePort) Set the control to connect to on the remote server.voidsetRetryCount(int retryCount) Set the retry count for retrying file transfers.voidsetRetryDelay(int retryDelay) Set the retry delay between retry attempts, in millisecondsvoidsetServerWakeupInterval(int interval) Set server wakeup interval in seconds.voidsetStrictReturnCodes(boolean strict) Set strict checking of FTP return codes.voidsetTimeout(int millis) Set the SO_TIMEOUT in milliseconds on the underlying socket.voidsetTransferBufferSize(int size) Set the size of the buffers used in writing to and reading from the data socketsvoidsetTransferCompleteMessages(TransferCompleteStrings transferCompleteStrings) Set a new instance of the strings classvoidsetType(FTPTransferType type) Set the transfer typebooleanRun a site-specific command on the server.longGet the size of a remote file.stat()Sends stat message to enquire about the status of a transfer.system()Get the type of the OS at the servertoString()String representationvoidSupply the user name to log into an account on the FTP server.voidvalidateReply(FTPReply reply, String expectedReplyCode) Validate an FTPReplyvoidvalidateReply(FTPReply reply, String[] expectedReplyCodes) Validate an FTPReplyvoidValidate that the put() or get() was successful.protected voidValidate a transfer when an error has occurred on the data channel.
-
Field Details
-
cvsId
Revision control id -
DEFAULT_MONITOR_INTERVAL
public static final int DEFAULT_MONITOR_INTERVALDefault byte interval for transfer monitor- See Also:
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZEDefault transfer buffer size- See Also:
-
DEFAULT_TIMEOUT
public static final int DEFAULT_TIMEOUTDefault timeout- See Also:
-
DEFAULT_RETRY_COUNT
public static final int DEFAULT_RETRY_COUNTDefault number of retries for file transfers- See Also:
-
DEFAULT_RETRY_DELAY
public static final int DEFAULT_RETRY_DELAYDefault retry delay in milliseconds- See Also:
-
DEFAULT_TCP_BUFFER_SIZE
public static final int DEFAULT_TCP_BUFFER_SIZEDefault SO_SNDBUF and SO_RCVBUF size- See Also:
-
DEFAULT_ENCODING
Default encoding used for control data- See Also:
-
LINE_SEPARATOR
public static byte[] LINE_SEPARATORLocal line separator -
CARRIAGE_RETURN
public static final byte CARRIAGE_RETURNUsed for ASCII translation- See Also:
-
LINE_FEED
public static final byte LINE_FEEDUsed for ASCII translation- See Also:
-
FTP_LINE_SEPARATOR
public static final byte[] FTP_LINE_SEPARATORUsed for ASCII translation -
DEFAULT_LISTING_LOCALES
Default locales -
control
Socket responsible for controlling the connection -
data
protected com.enterprisedt.net.ftp.internal.FTPDataSocket dataSocket responsible for transferring the data -
timeout
protected int timeoutSocket timeout for both data and control. In milliseconds -
serverWakeupInterval
protected int serverWakeupIntervalInterval in seconds in between server wakeups. O is not enabled -
remoteAddr
Address of the remote server. -
remoteHost
Name/IP of remote host -
id
Id of instance -
controlPort
protected int controlPortControl port number. -
controlEncoding
Encoding used on control socket -
dirEmptyStrings
Matcher for directory empty -
transferCompleteStrings
Matcher for transfer complete -
fileNotFoundStrings
Matcher for permission denied -
detectTransferMode
protected boolean detectTransferModeIf true, filetypes are autodetected and transfer mode changed to binary/ASCII as required -
fileLockingEnabled
protected boolean fileLockingEnabledIf true, file locking is used on local downloaded files to prevent other processes corrupting them -
monitorInterval
protected long monitorIntervalBytes transferred in between monitor callbacks -
transferBufferSize
protected int transferBufferSizeSize of transfer buffers -
dataReceiveBufferSize
protected int dataReceiveBufferSizeSize of data socket's receive buffer -
dataSendBufferSize
protected int dataSendBufferSizeSize of data socket's send buffer -
monitor
Progress monitor -
messageListener
Message listener -
monitorEx
File transfer listener -
transferType
Record of the transfer type - make the default ASCII -
lastValidReply
Holds the last valid reply from the server on the control socket -
lastReply
Holds the last reply from the server on the control socket -
user
Username cached -
password
Password cached -
throttler
Threshold for throttling -
dataChannelCallback
Pasv callback method -
useNOOP
protected boolean useNOOPNOOP supported?
-
-
Constructor Details
-
FTPClient
Deprecated.use setter methods to set propertiesConstructor. Creates the control socket- Parameters:
remoteHost- the remote hostname- Throws:
IOExceptionFTPException
-
FTPClient
Deprecated.use setter methods to set propertiesConstructor. Creates the control socket- Parameters:
remoteHost- the remote hostnamecontrolPort- port for control stream (-1 for default port)- Throws:
IOExceptionFTPException
-
FTPClient
Deprecated.use setter methods to set propertiesConstructor. Creates the control socket- Parameters:
remoteHost- the remote hostnamecontrolPort- 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:
IOExceptionFTPException
-
FTPClient
public FTPClient(String remoteHost, int controlPort, int timeout, String encoding) throws IOException, FTPException Deprecated.use setter methods to set propertiesConstructor. Creates the control socket- Parameters:
remoteHost- the remote hostnamecontrolPort- 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:
IOExceptionFTPException
-
FTPClient
Deprecated.use setter methods to set propertiesConstructor. Creates the control socket- Parameters:
remoteAddr- the address of the remote host- Throws:
IOExceptionFTPException
-
FTPClient
Deprecated.use setter methods to set propertiesConstructor. Creates the control socket. Allows setting of control port (normally set by default to 21).- Parameters:
remoteAddr- the address of the remote hostcontrolPort- port for control stream- Throws:
IOExceptionFTPException
-
FTPClient
public FTPClient(InetAddress remoteAddr, int controlPort, int timeout) throws IOException, FTPException Deprecated.use setter methods to set propertiesConstructor. Creates the control socket. Allows setting of control port (normally set by default to 21).- Parameters:
remoteAddr- the address of the remote hostcontrolPort- port for control stream (-1 for default port)timeout- the length of the timeout, in milliseconds (pass in 0 for no timeout)- Throws:
IOExceptionFTPException
-
FTPClient
public FTPClient(InetAddress remoteAddr, int controlPort, int timeout, String encoding) throws IOException, FTPException Deprecated.use setter methods to set propertiesConstructor. Creates the control socket. Allows setting of control port (normally set by default to 21).- Parameters:
remoteAddr- the address of the remote hostcontrolPort- 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:
IOExceptionFTPException
-
FTPClient
public FTPClient()Default constructor should now always be used together with setter methods in preference to other constructors (now deprecated). Theconnect()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 Details
-
getVersion
public static int[] getVersion()Get the version of edtFTPj- Returns:
- int array of {major,middle,minor} version numbers
-
getBuildTimestamp
Get the build timestamp- Returns:
- d-MMM-yyyy HH:mm:ss z build timestamp
-
connect
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:
connectin interfaceFTPClientInterface- 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:
connectedin interfaceFTPClientInterface- Returns:
- true if connected, false otherwise
-
checkConnection
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
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 offSwitch debug of responses on or off- Parameters:
on- true if you wish to have responses to the log stream, false otherwise
-
getId
Get the identifying string for this instance- Specified by:
getIdin interfaceFTPClientInterface- Returns:
- identifying string
-
setId
Set the identifying string for this instance- Specified by:
setIdin interfaceFTPClientInterface- Parameters:
id- identifying string
-
getDownloadCount
public int getDownloadCount()Get the number of files downloaded since the count was reset- Specified by:
getDownloadCountin interfaceFTPClientInterface- Returns:
- download file count
-
resetDownloadCount
public void resetDownloadCount()Reset the count of downloaded files to zero.- Specified by:
resetDownloadCountin interfaceFTPClientInterface
-
getUploadCount
public int getUploadCount()Get the number of files uploaded since the count was reset- Specified by:
getUploadCountin interfaceFTPClientInterface- Returns:
- upload file count
-
resetUploadCount
public void resetUploadCount()Reset the count of uploaded files to zero.- Specified by:
resetUploadCountin interfaceFTPClientInterface
-
getDeleteCount
public int getDeleteCount()Get the number of files deleted since the count was reset- Specified by:
getDeleteCountin interfaceFTPClientInterface- Returns:
- deleted file count
-
resetDeleteCount
public void resetDeleteCount()Reset the count of deleted files to zero.- Specified by:
resetDeleteCountin interfaceFTPClientInterface
-
setDataChannelCallback
Set the data channel callback, which notifies of the ip and port number to be connected to, and gives an opportunity to modify these values- Parameters:
callback- callback to set
-
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.
-
setListenOnAllInterfaces
public void setListenOnAllInterfaces(boolean listenOnAll) Listen on all interfaces for active mode transfers (the default).- Parameters:
listenOnAll- true if listen on all interfaces, false to listen on the control interface
-
getListenOnAllInterfaces
public boolean getListenOnAllInterfaces()Are we listening on all interfaces in active mode, which is the default?- Returns:
- true if listening on all interfaces, false if listening just on the control interface
-
getFileNotFoundMessages
Get class that holds fragments of server messages that indicate a file was not found. New messages can be added.The fragments are used when it is necessary to examine the message returned by a server to see if it is saying a file was not found. If an FTP server is returning a different message that still clearly indicates a file was not found, use this property to add a new server fragment to the repository via the add method. It would be helpful to email support at enterprisedt dot com to inform us of the message so it can be added to the next build.
- Returns:
- messages class
-
setFileNotFoundMessages
Set a new instance of the strings class- Parameters:
fileNotFoundStrings- new instance
-
getTransferCompleteMessages
Get class that holds fragments of server messages that indicate a transfer completed. New messages can be added.The fragments are used when it is necessary to examine the message returned by a server to see if it is saying a transfer completed. If an FTP server is returning a different message that still clearly indicates a transfer failed, use this property to add a new server fragment to the repository via the add method. It would be helpful to email support at enterprisedt dot com to inform us of the message so it can be added to the next build.
- Returns:
- messages class
-
setTransferCompleteMessages
Set a new instance of the strings class- Parameters:
transferCompleteStrings- new instance
-
getDirectoryEmptyMessages
Get class that holds fragments of server messages that indicate a directory is empty. New messages can be added.The fragments are used when it is necessary to examine the message returned by a server to see if it is saying a directory is empty. If an FTP server is returning a different message that still clearly indicates a directory is empty, use this property to add a new server fragment to the repository via the add method. It would be helpful to email support at enterprisedt dot com to inform us of the message so it can be added to the next build.
- Returns:
- messages class
-
setDirectoryEmptyMessages
Set a new instance of the strings class- Parameters:
dirEmptyStrings- new instance
-
setDetectTransferMode
public void setDetectTransferMode(boolean detectTransferMode) Description copied from interface:FTPClientInterfaceSet 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:
setDetectTransferModein interfaceFTPClientInterface- Parameters:
detectTransferMode- true if detecting transfer mode, false if not
-
getDetectTransferMode
public boolean getDetectTransferMode()Description copied from interface:FTPClientInterfaceGet the detect transfer mode- Specified by:
getDetectTransferModein interfaceFTPClientInterface- Returns:
- true if we are detecting binary and ASCII transfers from the file type
-
setFileLockingEnabled
public void setFileLockingEnabled(boolean lockingEnabled) Description copied from interface:FTPClientInterfaceSet file locking to enabled or disabled. When downloading files, by default the local file is locked for exclusive writing to prevent other processes corrupting it. Sometimes this needs to be disabled, e.g. tryLock() fails on NFS drives in versions of Java prior to 7.- Specified by:
setFileLockingEnabledin interfaceFTPClientInterface- Parameters:
lockingEnabled- true to enable locking, false to disable
-
getFileLockingEnabled
public boolean getFileLockingEnabled()Description copied from interface:FTPClientInterfaceDetermine if file locking on local downloaded files is being used or not. Default is true.- Specified by:
getFileLockingEnabledin interfaceFTPClientInterface- Returns:
- true if file locking is enabled, false otherwise
-
setForceUniqueNames
public void setForceUniqueNames(boolean forceUnique) Set to true if the STOU command is always to be used when uploading files, even if a filename is supplied. Normally STOU is only used if the supplied remote filename is null or the empty string.- Parameters:
forceUnique- true if STOU is always to be used
-
chooseTransferMode
Switch the transfer mode if requested and if necessary- Parameters:
filename- filename of file to be transferred- Throws:
FTPExceptionIOException
-
setTimeout
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 60,000 milliseconds. Note that for JREs 1.4+, the timeout is also used when first connecting to the remote host.- Specified by:
setTimeoutin interfaceFTPClientInterface- Parameters:
millis- The length of the timeout, in milliseconds- Throws:
IOException
-
getTimeout
public int getTimeout()Get the TCP timeout- Specified by:
getTimeoutin interfaceFTPClientInterface- 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 replacesgetControlPort().- Specified by:
getRemotePortin interfaceFTPClientInterface- Returns:
- Returns the port being connected to on the remote server.
-
setRemotePort
Set the control to connect to on the remote server. Can only do this if not already connected. Note that this method replacessetControlPort(int).- Specified by:
setRemotePortin interfaceFTPClientInterface- Parameters:
remotePort- The port to use.- Throws:
FTPException- Thrown if the client is already connected to the server.
-
getControlPort
public int getControlPort()Deprecated.UseFTPClientInterface.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
Deprecated.UseFTPClientInterface.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
- Returns:
- Returns the remoteAddr.
-
setRemoteAddr
Set the remote address- Parameters:
remoteAddr- The remoteAddr to set.- Throws:
FTPException
-
getRemoteHost
Description copied from interface:FTPClientInterfaceReturns the IP address or name of the remote host.- Specified by:
getRemoteHostin interfaceFTPClientInterface- Returns:
- Returns the remote host.
-
setRemoteHost
Description copied from interface:FTPClientInterfaceSet 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:
setRemoteHostin interfaceFTPClientInterface- 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. If proxies are used (e.g. SOCKS) then this setting is ignored.- 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
Get the encoding used for the control connection- Returns:
- Returns the current controlEncoding.
-
getNetworkBufferSize
public int getNetworkBufferSize()Get the size of the network buffers (SO_SNDBUF and SO_RCVBUF).- Specified by:
getNetworkBufferSizein interfaceFTPClientInterface- Returns:
- int
-
setNetworkBufferSize
public void setNetworkBufferSize(int networkBufferSize) Set the size of the network buffers (SO_SNDBUF and SO_RCVBUF).- Specified by:
setNetworkBufferSizein interfaceFTPClientInterface- Parameters:
networkBufferSize- new buffer size to set
-
setDataReceiveBufferSize
public void setDataReceiveBufferSize(int size) Deprecated.Set the size of the data socket's receive buffer.- Parameters:
size- must be > 0
-
getDataReceiveBufferSize
public int getDataReceiveBufferSize()Deprecated.Get the size of the data socket's receive buffer. A value of 0 means the defaults are being used.- Returns:
- size
-
setDataSendBufferSize
public void setDataSendBufferSize(int size) Deprecated.Set the size of the data socket's send buffer.- Parameters:
size- must be > 0
-
getDataSendBufferSize
public int getDataSendBufferSize()Deprecated.Get the size of the data socket's send buffer. A value of 0 means the defaults are being used.- Returns:
- size
-
setControlEncoding
Set the control socket's encoding. Can only do this if not connected- Specified by:
setControlEncodingin interfaceFTPClientInterface- Parameters:
controlEncoding- The controlEncoding to set, which is the name of a Charset- Throws:
FTPException- See Also:
-
getMessageListener
- Returns:
- Returns the messageListener.
-
setMessageListener
Set a listener that handles all FTP messages- Parameters:
listener- message listener
-
getProgressMonitorEx
Get reference to the transfer listener- Returns:
- FTPProgressMonitorEx
-
setProgressMonitorEx
Set reference to the transfer listener- Parameters:
monitorEx- transfer listener
-
setConnectMode
Set the connect mode- Parameters:
mode- ACTIVE or PASV mode
-
getConnectMode
- Returns:
- Returns the connectMode.
-
setProgressMonitor
Description copied from interface:FTPClientInterfaceSet 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:
setProgressMonitorin interfaceFTPClientInterface- Parameters:
monitor- the monitor objectinterval- bytes transferred in between callbacks
-
setProgressMonitor
Description copied from interface:FTPClientInterfaceSet a progress monitor for callbacks. Uses default callback interval- Specified by:
setProgressMonitorin interfaceFTPClientInterface- Parameters:
monitor- the monitor object
-
getProgressMonitor
Get the reference to the progress monitor- Returns:
- progress monitor
-
getMonitorInterval
public long getMonitorInterval()Description copied from interface:FTPClientInterfaceGet the bytes transferred between each callback on the progress monitor- Specified by:
getMonitorIntervalin interfaceFTPClientInterface- Returns:
- long bytes to be transferred before a callback
-
setMonitorInterval
public void setMonitorInterval(long interval) Set the number of bytes transferred between each callback on the progress monitor param interval 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:FTPClientInterfaceCancels 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:
cancelTransferin interfaceFTPClientInterface
-
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
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
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:
activeIP- IP address to force, in 192.168.1.0 form or in IPV6 form, e.g. 1080::8:800:200C:417A- Throws:
FTPException
-
getActiveIPAddress
Get the active IP address that is set.- Returns:
- active IP address or null if not set
-
setActivePortRange
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
-
getActiveLowPort
public int getActiveLowPort()Get the lower limit of the port range for active mode.- Returns:
- lower limit, or -1 if not set
-
getActiveHighPort
public int getActiveHighPort()Get the upper limit of the port range for active mode.- Returns:
- upper limit, or -1 if not set
-
login
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 namepassword- user's password- Throws:
IOExceptionFTPException
-
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 namepassword- user's passwordaccountInfo- account info string- Throws:
IOExceptionFTPException
-
user
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:
IOExceptionFTPException
-
password
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:
IOExceptionFTPException
-
account
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:
IOExceptionFTPException
-
initSOCKS
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 porthost- SOCKS proxy hostname
-
initSOCKSAuthentication
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 usernamepassword- the SOCKS password
-
clearSOCKS
public static void clearSOCKS()Clear SOCKS settings. Note that setting these properties affects all TCP sockets in this JVM -
quote
Issue arbitrary ftp commands to the FTP server.- Parameters:
command- ftp command to be sent to servervalidCodes- valid return codes for this command. If null is supplied no validation is performed- Returns:
- the text returned by the FTP server
- Throws:
IOExceptionFTPException
-
quote
Issue arbitrary ftp commands to the FTP server.- Parameters:
command- ftp command to be sent to server- Returns:
- the raw text returned by the FTP server including reply code
- Throws:
IOExceptionFTPException
-
executeCommand
Request that the remote server execute the literal command supplied. This is a synonym for the quote() command.- Specified by:
executeCommandin interfaceFTPClientInterface- Parameters:
command- command string- Returns:
- result string by server
- Throws:
FTPExceptionIOException
-
existsFile
Use to find out if a file exists or not. Since there is no reliable standard command to check the existence of a file, this method first tries to get the size of the file. If this fails then it tries to get the modtime and finally, if that fails will get a directory listing and look for the file in that listing.- Parameters:
remoteFile- File of which to check existence.- Returns:
- true if directory exists.
- Throws:
IOException- Thrown if there is a TCP/IP-related error.FTPException- Thrown if there is an error related to the FTP protocol.
-
existsDirectory
Use to find out if a directory exists or not. Since there is no reliable standard command to check the existence of a directory, this method tries to change into the directory and then changes back to the original directory.- Parameters:
remoteDirectory- Directory of which to check existence.- Returns:
- true if directory exists.
- Throws:
IOException- Thrown if there is a TCP/IP-related error.FTPException- Thrown if there is an error related to the FTP protocol.
-
exists
Deprecated.Use existsFile(String).Description copied from interface:FTPClientInterfaceDoes the named file exist in the current server directory?- Specified by:
existsin interfaceFTPClientInterface- Parameters:
remoteFile- name of remote file- Returns:
- true if exists, false otherwise
- Throws:
IOExceptionFTPException
-
sendCommand
Send a command to the server and get the reply- Parameters:
command- command- Returns:
- FTPReply
- Throws:
IOExceptionFTPException
-
validateReply
Validate an FTPReply- Parameters:
reply- reply objectexpectedReplyCode- expected code- Throws:
FTPException
-
validateReply
Validate an FTPReply- Parameters:
reply- reply objectexpectedReplyCodes- expected codes- Throws:
FTPException
-
size
Description copied from interface:FTPClientInterfaceGet 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:
sizein interfaceFTPClientInterface- Parameters:
remoteFile- name or path of remote file in current directory- Returns:
- size of file in bytes
- Throws:
IOExceptionFTPException
-
resume
Description copied from interface:FTPClientInterfaceMake 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:
resumein interfaceFTPClientInterface- Throws:
FTPException
-
resumeNextDownload
Description copied from interface:FTPClientInterfaceMake the next download resume at a specific point. This resume method allows the resume offset to be set explicitly for downloads. Offset bytes are skipped before downloading the file. This means you can download only the last few bytes of the file rather than the whole file, irrespective of the size of the local file. Currently resume is only supported for BINARY transfers (which is generally what it is most useful for).- Specified by:
resumeNextDownloadin interfaceFTPClientInterface- Throws:
FTPException
-
cancelResume
Description copied from interface:FTPClientInterfaceCancel the resume. Use this method if something goes wrong and the server is left in an inconsistent state- Specified by:
cancelResumein interfaceFTPClientInterface- Throws:
IOExceptionFTPException
-
forceResumeOff
protected void forceResumeOff()Force the resume flag off. Internal use only. -
restart
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:
IOExceptionFTPException
-
getRetryCount
public int getRetryCount()Get the retry count for retrying file transfers. Default is 3 attempts.- Returns:
- number of times a transfer is retried
-
setRetryCount
public void setRetryCount(int retryCount) Set the retry count for retrying file transfers.- Parameters:
retryCount- new retry count
-
getRetryDelay
public int getRetryDelay()Get the retry delay between retry attempts, in milliseconds. Default is 5000.- Returns:
- retry delay in milliseconds
-
setRetryDelay
public void setRetryDelay(int retryDelay) Set the retry delay between retry attempts, in milliseconds- Parameters:
new- retry delay in milliseconds
-
get
Description copied from interface:FTPClientInterfaceGet data from the FTP server. Uses the currently set transfer mode.- Specified by:
getin interfaceFTPClientInterface- Parameters:
localPath- local file to put data inremoteFile- name of remote file in current directory- Throws:
IOExceptionFTPException
-
put
public String put(InputStream srcStream, String remoteFile, boolean append) throws IOException, FTPException Description copied from interface:FTPClientInterfacePut 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:
putin interfaceFTPClientInterface- Parameters:
srcStream- input stream of data to putremoteFile- name of remote file in current directory, or null if a unique filename is to be generated by the serverappend- 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:
IOExceptionFTPException
-
reconnect
Reconnect to the server- Parameters:
cwd- current working dir- Throws:
IOExceptionFTPException
-
put
Description copied from interface:FTPClientInterfacePut 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:
putin interfaceFTPClientInterface- Parameters:
localPath- path of the local fileremoteFile- 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:
IOExceptionFTPException
-
put
Description copied from interface:FTPClientInterfacePut 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:
putin interfaceFTPClientInterface- Parameters:
srcStream- input stream of data to putremoteFile- 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:
IOExceptionFTPException
-
put
public String put(String localPath, String remoteFile, boolean append) throws IOException, FTPException Description copied from interface:FTPClientInterfacePut 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:
putin interfaceFTPClientInterface- Parameters:
localPath- path of the local fileremoteFile- name of remote file in current directory, or null if a unique filename is to be generated by the serverappend- 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:
IOExceptionFTPException
-
validateTransfer
Validate that the put() or get() was successful. This method is not for general use.- Throws:
IOExceptionFTPException
-
validateTransferOnError
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:
IOExceptionFTPException
-
closeDataSocket
Close stream for data socket. Not for general use!- Parameters:
stream- stream reference
-
closeDataSocket
Close stream for data socket- Parameters:
stream- stream reference
-
createDataSocket
Set up the data socket- Throws:
FTPExceptionIOException
-
configureDataSocket
- Throws:
IOException
-
initPut
Request the server to set up the put- Parameters:
remoteFile- name of remote file in current directoryappend- true if appending, false otherwise- Throws:
IOExceptionFTPException
-
put
Description copied from interface:FTPClientInterfacePut 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:
putin interfaceFTPClientInterface- Parameters:
bytes- array of bytesremoteFile- 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:
IOExceptionFTPException
-
put
Description copied from interface:FTPClientInterfacePut 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:
putin interfaceFTPClientInterface- Parameters:
bytes- array of bytesremoteFile- name of remote file in current directory, or null if a unique filename is to be generated by the serverappend- 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:
IOExceptionFTPException
-
postTransferChecks
protected void postTransferChecks(String localPath, String remotePath, FTPTransferType transferType, boolean append) throws FTPException, IOException Can be overridden by subclasses to do any necessary post transfer checking.- Parameters:
localPath- local fileremotePath- remote filetransferType- binary or ASCIIappend-- Throws:
FTPExceptionIOException
-
postTransferChecks
protected void postTransferChecks(byte[] localBytes, String remotePath, FTPTransferType transferType, boolean append) throws FTPException, IOException Can be overridden by subclasses to do any necessary post transfer checking.- Parameters:
localBytes- local bytes to transferremotePath- remote filetransferType- binary or ASCIIappend-- Throws:
FTPExceptionIOException
-
get
Description copied from interface:FTPClientInterfaceGet data from the FTP server. Uses the currently set transfer mode.- Specified by:
getin interfaceFTPClientInterface- Parameters:
destStream- data stream to write data toremoteFile- name of remote file in current directory- Throws:
IOExceptionFTPException
-
resetTransferMode
Reset the transfer mode back to what it should be, if it has changed.- Parameters:
previousType- previous transfer type- Throws:
IOExceptionFTPException
-
initGet
Request to the server that the get is set up- Parameters:
remoteFile- name of remote file- Throws:
IOExceptionFTPException
-
getInputStream
Get the data input stream. Not for general use!- Returns:
- Throws:
IOException
-
getOutputStream
Get the data input stream. Not for general use!- Returns:
- Throws:
IOException
-
get
Description copied from interface:FTPClientInterfaceGet 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:
getin interfaceFTPClientInterface- Parameters:
remoteFile- name of remote file in current directory- Throws:
IOExceptionFTPException
-
site
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:
IOExceptionFTPException
-
list
Deprecated.As of FTP 1.1, replaced bydir(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:
IOExceptionFTPException
-
list
Deprecated.As of FTP 1.1, replaced bydir(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:
IOExceptionFTPException
-
setFTPFileFactory
Override the chosen file factory with a user created one - meaning that a specific parser has been selected- Parameters:
fileFactory-
-
setParserLocale
Deprecated.@see FTPClient#setParserLocales(Locale[])Set the locale for date parsing of dir listings- Parameters:
locale- new locale to use
-
setParserLocales
Set the list of locales to be tried for date parsing of dir listings- Parameters:
locales- locales to use
-
fileDetails
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, and the fallback is to use the SIZE and MDTM commands.- Parameters:
name- name of a file- Returns:
- if it exists, an FTPFile object
- Throws:
IOExceptionFTPExceptionParseException
-
dirDetailsM
Uses the MLSD command to find out details about the named directory. A directory name should be supplied.- Parameters:
name- name of a directory- Returns:
- an FTPFile array
- Throws:
IOExceptionFTPExceptionParseException
-
dirDetails
public void dirDetails(String dirname, DirectoryListCallback lister) throws IOException, FTPException, ParseException Description copied from interface:FTPClientInterfaceList a directory's contents via a callback. The callback is notified for each directory entry, meaning they can be processed individually. It also avoids out of memory problems if the directory is huge, and an array of thousands of FTPFile objects would otherwise be returned. Most servers return an empty directory listing if a directory does not exist, and this is also what this method does. To establish whether or not a directory exists, try changing into it.- Specified by:
dirDetailsin interfaceFTPClientInterface- Parameters:
dirname- name of directory (some servers permit a filemask)lister- callback to be notified of errors- Throws:
IOExceptionFTPExceptionParseException
-
dirDetails
Description copied from interface:FTPClientInterfaceList a directory's contents as an array of FTPFile objects. Most servers return an empty directory listing if a directory does not exist, and this is also what this method does. To establish whether or not a directory exists, try changing into it. 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:
dirDetailsin interfaceFTPClientInterface- Parameters:
dirname- name of directory (some servers permit a filemask)- Returns:
- an array of FTPFile objects
- Throws:
IOExceptionFTPExceptionParseException
-
dir
Description copied from interface:FTPClientInterfaceList current directory's contents as an array of strings of filenames. Most servers return an empty directory listing if a directory does not exist, and this is also what this method does. To establish whether or not a directory exists, try changing into it.- Specified by:
dirin interfaceFTPClientInterface- Returns:
- an array of current directory listing strings
- Throws:
IOExceptionFTPException
-
dir
Description copied from interface:FTPClientInterfaceList a directory's contents as an array of strings of filenames. Most servers return an empty directory listing if a directory does not exist, and this is also what this method does. To establish whether or not a directory exists, try changing into it.- Specified by:
dirin interfaceFTPClientInterface- Parameters:
dirname- name of directory OR filemask- Returns:
- an array of directory listing strings
- Throws:
IOExceptionFTPException
-
dir
Description copied from interface:FTPClientInterfaceList 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. Most servers return an empty directory listing if a directory does not exist, and this is also what this method does. To establish whether or not a directory exists, try changing into it.- Specified by:
dirin interfaceFTPClientInterface- Parameters:
dirname- name of directory OR filemaskfull- true if detailed listing required false otherwise- Returns:
- an array of directory listing strings
- Throws:
IOExceptionFTPException
-
readChunk
Attempts to read a specified number of bytes from the givenInputStreamand 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- TheInputStreamto 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.
-
readChunk
public int readChunk(BufferedInputStream in, byte[] chunk, int offset, int chunksize) throws IOException Attempts to read a specified number of bytes from the givenInputStreamand 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- TheInputStreamto read from.chunk- The byte-array to place read bytes in.offset- Offset into chunkchunksize- Number of bytes to read.- Returns:
- Number of bytes actually read.
- Throws:
IOException- Thrown if there was an error while reading.
-
readChar
Attempts to read a single character from the givenInputStream. The purpose of this method is to permit subclasses to execute any additional code necessary when performing this operation.- Parameters:
in- TheLineNumberReaderto read from.- Returns:
- The character read.
- Throws:
IOException- Thrown if there was an error while reading.
-
readLine
Attempts to read a single line from the givenInputStream. The purpose of this method is to permit subclasses to execute any additional code necessary when performing this operation.- Parameters:
in- TheLineNumberReaderto read from.- Returns:
- The string read.
- Throws:
IOException- Thrown if there was an error while reading.
-
getLastValidReply
Gets the latest valid reply from the server- Returns:
- reply object encapsulating last valid server response
-
getLastReply
Gets the last reply from the server, whether valid or not- Returns:
- reply object encapsulating last server response
-
getType
Get the current transfer type- Specified by:
getTypein interfaceFTPClientInterface- Returns:
- the current type of the transfer, i.e. BINARY or ASCII
-
setType
Set the transfer type- Specified by:
setTypein interfaceFTPClientInterface- Parameters:
type- the transfer type to set the server to- Throws:
IOExceptionFTPException
-
delete
Description copied from interface:FTPClientInterfaceDelete the specified remote file- Specified by:
deletein interfaceFTPClientInterface- Parameters:
remoteFile- name of remote file to delete- Throws:
IOExceptionFTPException
-
rename
Description copied from interface:FTPClientInterfaceRename a file or directory- Specified by:
renamein interfaceFTPClientInterface- Parameters:
from- name of file or directory to renameto- intended name- Throws:
IOExceptionFTPException
-
rmdir
Description copied from interface:FTPClientInterfaceDelete the specified remote working directory- Specified by:
rmdirin interfaceFTPClientInterface- Parameters:
dir- name of remote directory to delete- Throws:
IOExceptionFTPException
-
mkdir
Description copied from interface:FTPClientInterfaceCreate the specified remote working directory- Specified by:
mkdirin interfaceFTPClientInterface- Parameters:
dir- name of remote directory to create- Throws:
IOExceptionFTPException
-
chdir
Description copied from interface:FTPClientInterfaceChange the remote working directory to that supplied- Specified by:
chdirin interfaceFTPClientInterface- Parameters:
dir- name of remote directory to change to- Throws:
IOExceptionFTPException
-
cdup
Description copied from interface:FTPClientInterfaceChange the remote working directory to the parent directory- Specified by:
cdupin interfaceFTPClientInterface- Throws:
IOExceptionFTPException
-
modtime
Description copied from interface:FTPClientInterfaceGet 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 time zone is UTC.- Specified by:
modtimein interfaceFTPClientInterface- Parameters:
remoteFile- name of remote file- Throws:
IOExceptionFTPException
-
setModTime
Description copied from interface:FTPClientInterfaceSet the last modified time (UTC) for the supplied file. This is not supported by all servers.- Specified by:
setModTimein interfaceFTPClientInterface- Parameters:
remoteFile- the path to the file/directory on the remote servermodTime- the time stamp to set the modified time to in UTC- Throws:
IOExceptionFTPException
-
pwd
Description copied from interface:FTPClientInterfaceGet the current remote working directory- Specified by:
pwdin interfaceFTPClientInterface- Returns:
- the current working directory
- Throws:
IOExceptionFTPException
-
features
Get the server supplied features- Returns:
- string containing server features, or null if no features or not supported
- Throws:
IOExceptionFTPException
-
system
Get the type of the OS at the server- Specified by:
systemin interfaceFTPClientInterface- Returns:
- the type of server OS
- Throws:
IOExceptionFTPException
-
noOperation
Send a "no operation" message that does nothing. Can be called periodically to prevent the connection timing out- Throws:
IOExceptionFTPException
-
noOp
Send the NOOP message- Throws:
IOExceptionFTPException
-
stat
Sends stat message to enquire about the status of a transfer.- Throws:
IOExceptionFTPException
-
sendServerWakeup
Wake up the server during a transfer to prevent a timeout from occuring. This may hang or confuse the server - use with caution.- Throws:
IOExceptionFTPException
-
keepAlive
Tries to keep the current connection alive by sending an innocuous command to signal that the client is still active- Specified by:
keepAlivein interfaceFTPClientInterface- Throws:
IOExceptionFTPException
-
help
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:
IOExceptionFTPException
-
abort
Abort the current action- Throws:
IOExceptionFTPException
-
quit
Description copied from interface:FTPClientInterfaceQuit the FTP session- Specified by:
quitin interfaceFTPClientInterface- Throws:
IOExceptionFTPException
-
quitImmediately
Description copied from interface:FTPClientInterfaceQuit the FTP session immediately. If a transfer is underway it will be terminated.- Specified by:
quitImmediatelyin interfaceFTPClientInterface- Throws:
IOExceptionFTPException
-
toString
String representation
-