Package com.enterprisedt.net.ftp
Class SecureFileTransferClient
java.lang.Object
com.enterprisedt.net.ftp.SecureFileTransferClient
- All Implemented Interfaces:
FileTransferClientInterface
- Direct Known Subclasses:
AsyncFileTransferClient
File transfer client class that supports multiple protocols and permits concurrent
FTP operations. A configurable connection pool provides the ability to perform multiple transfers
simultaneously from different threads.
Multiple protocols are supported, including 'plain' FTP, SFTP (FTP over SSH), and FTPS (FTP over SSL - both implicit and explicit modes). The protocol can be changed with a single method call.
A simple example is shown below:
SecureFileTransferClient client = new SecureFileTransferClient();
client.setRemoteHost(host);
client.setUserName(user);
client.setPassword(password);
client.setProtocol(Protocol.FTP); // FTP is the default
// connect
client.connect();
// perform a transfer, uploading the local file as 'remote.txt'
client.uploadFile("local.txt", "remote.txt");
// disconnect from server
client.disconnect();
Users should note that calling connect() starts a pool of worker threads and the connection pool. This means that disconnect() must be called to stop the worker threads, otherwise applications will hang on exit as threads will still be alive.
- Version:
- $Revision$
- Author:
- Bruce Blackshaw
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected HashMapActive transfer tasks, hashed on idprotected AdvancedFTPSettingsAdvanced configuration parameters that often aren't usedprotected AdvancedGeneralSettingsprotected AdvancedSSHSettingsprotected AdvancedSSLSettingsprotected com.enterprisedt.net.ftp.async.internal.AsyncFileTransferClientImplprotected EventListenerNotifies of various eventsprotected com.enterprisedt.net.ftp.async.internal.SecureConnectionContextConnection contextprotected MultipleTransferSettingsprotected ProxySettings -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.SecureFileTransferClient(int initialPoolSize, int maxPoolSize) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddErrorListener(ErrorListener listener) Add an error listener to the list of listenersvoidCancel all transfers that are either pending or currently under wayvoidchangeDirectory(String directoryName) Change directory on the FTP server.booleanIf true (the default), when paths are supplied as part of filenames, the directory is changed into before transferring the file,e.g.voidChange to parent directory on the FTP server.protected voidcheckConnection(boolean shouldBeConnected) Checks if the client has connected to the server and throws an exception if it hasn't.voidconnect()Make a connection to the FTP server.voidcreateDirectory(String directoryName) Create directory on the FTP server.voiddeleteDirectory(String directoryName) Delete a directory on the FTP server.voiddeleteDirectory(String directoryName, boolean recursive) Delete a directory on the FTP server, and optionally sub-directories.voiddeleteFile(String remoteFileName) Deletes a remote file.voiddeleteMultipleFiles(FileFilter filter) Deletes remote files in the current directory that match the supplied filename filtervoiddeleteMultipleFiles(String wildcard) Deletes remote files in the current directory that match the supplied wildcardvoiddeleteMultipleFiles(String remoteDirectory, FileFilter filter, boolean recursive) Deletes remote files in the current directory.voiddeleteMultipleFiles(String remoteDirectory, String wildcard, boolean recursive) Deletes remote files in the current directory.FTPFile[]List the current directory on the FTP server.FTPFile[]directoryList(String directoryName) List a directory on the FTP server.voiddirectoryList(String directoryName, DirectoryListCallback lister) List a directory on the FTP server, calling the user-supplied callback for each entry.String[]List the names of files and directories in the current directory on the FTP server.String[]directoryNameList(String directoryName, boolean isLongListing) List a directory on the FTP server.voidDisconnect from the FTP server.voiddisconnect(boolean immediate) Disconnect from the FTP server immediately.byte[]downloadByteArray(String remoteFileName) Download a file from the FTP server into a byte array.voiddownloadFile(String localFileName, String remoteFileName) Download a file from the FTP server .voiddownloadFile(String localFileName, String remoteFileName, WriteMode writeMode) Download a file from the FTP server .voiddownloadMultiple(String localDir, FileFilter filter) Downloads remote files to the supplied local directory that match the supplied wildcard from the current remote directory.voiddownloadMultiple(String localDir, String wildcard) Downloads remote files to the supplied local directory that match the supplied wildcard from the current remote directory.voiddownloadMultiple(String localDir, String remoteDir, FileFilter filter, boolean recursive) Downloads remote files to the supplied local directory that match the supplied FileFilter from the current remote directory.voiddownloadMultiple(String localDir, String remoteDir, String wildcard, boolean recursive) Downloads remote files to the supplied local directory that match the supplied wildcard from the current remote directory.downloadStream(String remoteFileName) Download a file from the FTP server as a stream.static voiddownloadURLFile(String localFileName, String ftpURL) Downloads the given file to the given FTP URL.static FileTransferInputStreamdownloadURLStream(String ftpURL) Open an InputStream for the given FTP URL.executeCommand(String command) Request that the remote server execute the literal command supplied.booleanDetermine if a remote file exists.booleanexistsDirectory(String remoteDir) Determine if a remote directory exists.voidfinalize()Finalize this instance by shutting down its threadsGet the advanced FTP configuration parameters objectGet the advanced general configuration parameters object, for none protocol specific parametersGet the advanced SSH configuration parameters objectGet the advanced SSL configuration parameters objectGet the current content type for all connections.Returns the initial remote directory that all connections change to immediately on connection.Gets the last FTP reply from the server, whether valid or not.intGet the maximum bandwidth for transfersgetModifiedTime(String remoteFileName) Get the modified-time of a remote file.Get the configuration object that controls the settings used for multiple transfersintGet the size of the network buffers (SO_SNDBUF and SO_RCVBUF).Get the current user password.Get the current protocol being usedGet the proxy settings instance.Get the current remote directory of the master context.Returns the IP address or name of the remote host.intReturns the port being connected to on the remote server.longGet the size of a remote file.Get statistics on file transfers and deletions.Get a string that represents the remote system that the client is logged into.intReturns the timeout for socket connections.Get the current user name.booleanIs compression enabled?booleanIs this client currently connected to the server?booleanGet the detect content type flagbooleanIs the connection pool's keep alive thread enabled, i.e.booleanIs server validation switched on, i.e.booleanIs integrity checking of transfers enabled?voidloadSSHServerValidation(String knownHosts) Load the public keys that the server public key will be validated against.voidloadSSLServerValidation(String rootCertificatesPath) Load the root certificates that the server certificate will be validated against.voidRename a remote file or directory.voidsetChangeIntoPathDirectory(boolean changeIntoPathDirectory) Determine if when a path is supplied as part of a filename, whether the directory is changed into before transferring the file, e.g.voidsetCompressionPreferred(boolean enabled) Set compression flag on or off.voidSet the transfer type for all connections, either ASCII or binary.voidsetDetectContentType(boolean detectContentType) Set auto detect of filetypes on or off.voidsetEventListener(EventListener listener) Set the event listener for transfer event notificationvoidsetInitialRemoteDirectory(String directory) Set the initial remote directory that all connections change to immediately on connection.voidsetKeepAliveEnabled(boolean enabled) Change the connection pool keep alive setting, switching it on or off.voidsetMaxTransferRate(int thresholdBytesPerSecond) Set the maximum transfer rates in bytes per secvoidsetModifiedTime(String remoteFileName, Date modifiedTime) Set the modified-time of a remote file.voidsetNetworkBufferSize(int networkBufferSize) Set the size of the network buffers (SO_SNDBUF and SO_RCVBUF).voidsetPassword(String password) Set the password of the user to log in with.voidsetPermissions(String remotePath, int permissions) Set the permissions of the supplied file or directory.voidsetProtocol(Protocol protocol) Set the current protocol to be used.voidsetRemoteHost(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 port to connect to on the remote server.voidsetServerValidationEnabled(boolean enabled) Change the server validation setting, switching it on or off.voidsetTimeout(int timeout) Set the timeout for socket connections.voidsetTransferIntegrityCheck(boolean enabled) Enable or disable integrity checks on transfers.voidsetUserName(String userName) Set the name of the user to log in with.protected voidshutdown(boolean immediate) Shutdown all the worker threads in the task processor.uploadByteArray(byte[] bytes, String remoteFileName, WriteMode writeMode) Upload a byte array to the FTP server.uploadFile(String localFileName, String remoteFileName) Upload a file to the FTP server.uploadFile(String localFileName, String remoteFileName, WriteMode writeMode) Upload a file to the FTP server.voiduploadMultiple(String localDir, FileFilter filter) Uploads local files from the supplied local directory that match the supplied FileFilter into the current remote directory.voiduploadMultiple(String localDir, String wildcard) Uploads local files from the supplied local directory that match the supplied wildcard into the current remote directory.voiduploadMultiple(String localDir, String remoteDir, FileFilter filter, boolean recursive) Uploads local files from the supplied local directory that match the supplied wildcard into the supplied remote directory.voiduploadMultiple(String localDir, String remoteDir, String wildcard, boolean recursive) Uploads local files from the supplied local directory that match the supplied wildcard into the supplied remote directory.uploadStream(String remoteFileName) Upload a file to the FTP server by writing to a stream.uploadStream(String remoteFileName, WriteMode writeMode) Upload a file to the FTP server by writing to a stream.static voiduploadURLFile(String localFileName, String ftpURL) Uploads the given file to the given FTP URL.static FileTransferOutputStreamuploadURLStream(String ftpURL) Open an OutputStream for the given FTP URL.
-
Field Details
-
asyncImpl
protected com.enterprisedt.net.ftp.async.internal.AsyncFileTransferClientImpl asyncImpl -
masterContext
protected com.enterprisedt.net.ftp.async.internal.SecureConnectionContext masterContextConnection context -
activeTransferTasks
Active transfer tasks, hashed on id -
eventListener
Notifies of various events -
multiSettings
-
proxySettings
-
advancedFTPSettings
Advanced configuration parameters that often aren't used -
advancedSettings
-
advancedSSLSettings
-
advancedSSHSettings
-
-
Constructor Details
-
SecureFileTransferClient
public SecureFileTransferClient(int initialPoolSize, int maxPoolSize) Constructor. Initialises the class.- Parameters:
initialPoolSize- initial size of connection pool (i.e. number of managed connections).maxPoolSize- maximum size of pool.
-
SecureFileTransferClient
public SecureFileTransferClient()Constructor. Initialises the class. Uses a default initial and maximum pool size.
-
-
Method Details
-
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.
-
getRemoteHost
Returns the IP address or name of the remote host.- Specified by:
getRemoteHostin interfaceFileTransferClientInterface- Returns:
- Returns the remote host.
-
setRemoteHost
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:
setRemoteHostin interfaceFileTransferClientInterface- Parameters:
remoteHost- The IP address or name of the remote host- Throws:
FTPException- Thrown if the client is already connected to the server.
-
getProtocol
Get the current protocol being used- Returns:
- Protocol
-
setProtocol
Set the current protocol to be used. Cannot be connected. The port number is automatically reset to the default for the new protocol, and so setRemotePort should be called after this method if a different port is required.- Parameters:
protocol- protocol to use- Throws:
FTPException
-
getProxySettings
Get the proxy settings instance. Its properties can be set to use proxies.- Returns:
- ProxySettings
-
getTimeout
public int getTimeout()Returns the timeout for socket connections.- Specified by:
getTimeoutin interfaceFileTransferClientInterface- Returns:
- Returns the connection timeout in milliseconds
-
setTimeout
Set the timeout for socket connections. Can only do this if not already connected.- Specified by:
setTimeoutin interfaceFileTransferClientInterface- Parameters:
timeout- the timeout to use in milliseconds- Throws:
FTPException- Thrown if the client is already connected to the server.
-
getNetworkBufferSize
public int getNetworkBufferSize()Get the size of the network buffers (SO_SNDBUF and SO_RCVBUF).- Specified by:
getNetworkBufferSizein interfaceFileTransferClientInterface- Returns:
- network buffer size
-
setNetworkBufferSize
Set the size of the network buffers (SO_SNDBUF and SO_RCVBUF).- Specified by:
setNetworkBufferSizein interfaceFileTransferClientInterface- Parameters:
networkBufferSize- new buffer size to set- Throws:
FTPException
-
getRemotePort
public int getRemotePort()Returns the port being connected to on the remote server.- Specified by:
getRemotePortin interfaceFileTransferClientInterface- Returns:
- Returns the port being connected to on the remote server.
-
setRemotePort
Set the port to connect to on the remote server. Can only do this if not already connected. This should be done after setting the protocol, as setting the protocol sets the port to the default value for that protocol.- Specified by:
setRemotePortin interfaceFileTransferClientInterface- Parameters:
remotePort- The port to use.- Throws:
FTPException- Thrown if the client is already connected to the server.
-
setContentType
Set the transfer type for all connections, either ASCII or binary. Setting applies to all subsequent transfers that are initiated. It does not apply to transfers currently in progress.- Specified by:
setContentTypein interfaceFileTransferClientInterface- Parameters:
type- transfer type- Throws:
IOExceptionFTPExceptionFTPException
-
getContentType
Get the current content type for all connections.- Specified by:
getContentTypein interfaceFileTransferClientInterface- Returns:
- transfer type
-
setDetectContentType
public void setDetectContentType(boolean detectContentType) Set auto detect 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:
setDetectContentTypein interfaceFileTransferClientInterface- Parameters:
detectContentType- true if detecting content type, false if not
-
isDetectContentType
public boolean isDetectContentType()Get the detect content type flag- Specified by:
isDetectContentTypein interfaceFileTransferClientInterface- Returns:
- true if we are detecting binary and ASCII transfers from the file type
-
setUserName
Set the name of the user to log in with. Can only do this if not already connected.- Specified by:
setUserNamein interfaceFileTransferClientInterface- Parameters:
userName- user-name to log in with.- Throws:
FTPException
-
getPassword
Get the current user password.- Specified by:
getPasswordin interfaceFileTransferClientInterface- Returns:
- current user password
-
setPassword
Set the password of the user to log in with. Can only do this if not already connected.- Specified by:
setPasswordin interfaceFileTransferClientInterface- Parameters:
password- password to log in with.- Throws:
FTPException
-
getUserName
Get the current user name.- Specified by:
getUserNamein interfaceFileTransferClientInterface- Returns:
- current user name
-
setMaxTransferRate
public void setMaxTransferRate(int thresholdBytesPerSecond) Set the maximum transfer rates in bytes per sec- Parameters:
thresholdBytesPerSecond- maximum bytes per second to transfer
-
getMaxTransferRate
public int getMaxTransferRate()Get the maximum bandwidth for transfers- Returns:
- threshold bytes per second, or -1 if no threshold
-
isTransferIntegrityCheck
public boolean isTransferIntegrityCheck()Is integrity checking of transfers enabled?- Returns:
- true if enabled, false otherwise
-
setTransferIntegrityCheck
public void setTransferIntegrityCheck(boolean enabled) Enable or disable integrity checks on transfers. This is currently not supported for SFTP, only for FTP and FTPS. It also relies on the XCRC command being supported in the FTP server that is being connected to. An exception will be thrown for the transfer if integrity checking is found to be unsupported in FTP/FTPS, or if the integrity check fails.- Parameters:
enabled- true if enabled, false otherwise
-
isCompressionPreferred
public boolean isCompressionPreferred()Is compression enabled?- Returns:
- true if enabled, false if not
-
setCompressionPreferred
public void setCompressionPreferred(boolean enabled) Set compression flag on or off. For FTP/FTPS this will enable MODE Z compression, and for SFTP it will enable zlib compression. In either case the server must be able to support compression for it to be used. It will silently fail if this is not the case, i.e. the data will not be compressed. Use the log files to confirm that compression is being used. Note that once enabled, the connection must be closed and re-opened to disable compression.- Parameters:
enabled- true to enable, false to disable.
-
getAdvancedFTPSettings
Get the advanced FTP configuration parameters object- Specified by:
getAdvancedFTPSettingsin interfaceFileTransferClientInterface- Returns:
- advanced parameters
-
getAdvancedSettings
Get the advanced general configuration parameters object, for none protocol specific parameters- Specified by:
getAdvancedSettingsin interfaceFileTransferClientInterface- Returns:
- advanced parameters
-
getAdvancedSSLSettings
Get the advanced SSL configuration parameters object- Returns:
- advanced parameters
-
getAdvancedSSHSettings
Get the advanced SSH configuration parameters object- Returns:
- advanced parameters
-
getMultipleTransferSettings
Get the configuration object that controls the settings used for multiple transfers- Returns:
- MultipleTransferSettings
-
changeIntoPathDirectory
public boolean changeIntoPathDirectory()If true (the default), when paths are supplied as part of filenames, the directory is changed into before transferring the file,e.g. if /path/fileA.name is supplied, then commands sent to the server are CD /path followed by STORE fileA.name. If false, the supplied path is used, e.g. if /path/fileA.name is supplied, then the command sent to the server is "STOR /path/fileA.name".- Returns:
- true if changing into directory, false otherwise.
-
setChangeIntoPathDirectory
public void setChangeIntoPathDirectory(boolean changeIntoPathDirectory) Determine if when a path is supplied as part of a filename, whether the directory is changed into before transferring the file, e.g. if /path/fileA.name is supplied, then commands sent to the server are CD /path followed by STORE fileA.name. If false, the supplied path is used, e.g. if /path/fileA.name is supplied, then the command sent to the server is "STOR /path/fileA.name". If thousands of files are being transferred rapidly, and many CD commands are observed in the log, try switching this off.- Parameters:
changeIntoPathDirectory- set whether or not the client should change into the path supplied
-
isServerValidationEnabled
public boolean isServerValidationEnabled()Is server validation switched on, i.e. is the identify of the server as presented via its certificate (SSL) or public key (SSH) verified by checking a certificate store or known hosts file? The default is disabled. In production systems server validation should always be enabled.- Returns:
- true if enabled, false if not enabled.
-
setServerValidationEnabled
Change the server validation setting, switching it on or off. If server validation is on, the identify of the server as presented via its certificate (SSL) or public key (SSH) is verified by checking a certificate store or known hosts file. The default is disabled. In production systems server validation should always be enabled.- Parameters:
enabled- true to enable, false to disable- Throws:
FTPException
-
isKeepAliveEnabled
public boolean isKeepAliveEnabled()Is the connection pool's keep alive thread enabled, i.e. will connections in the thread pool be regularly pinged to ensure they are maintained as live connections? Enabled by default.- Returns:
- true if enabled, false if not enabled.
-
setKeepAliveEnabled
Change the connection pool keep alive setting, switching it on or off. If the connection pool's keep alive thread is enabled, connections in the thread pool be regularly pinged to ensure they are maintained as live connections. Enabled by default.- Parameters:
enabled- true to enable, false to disable- Throws:
FTPException
-
loadSSLServerValidation
public void loadSSLServerValidation(String rootCertificatesPath) throws FileNotFoundException, IOException, FTPException Load the root certificates that the server certificate will be validated against. Note that this sets server validation to enabled. This is used for the FTPS protocol.- Parameters:
rootCertificatesPath- path to root certificates- Throws:
FileNotFoundExceptionIOExceptionFTPException
-
loadSSHServerValidation
public void loadSSHServerValidation(String knownHosts) throws FileNotFoundException, IOException, FTPException Load the public keys that the server public key will be validated against. They are typically stored in a file called 'known_hosts'. Note that this sets server validation to enabled. This is used for the SFTP protocol.- Parameters:
knownHosts- path to known hosts file- Throws:
FileNotFoundExceptionIOExceptionFTPException
-
isConnected
public boolean isConnected()Is this client currently connected to the server?- Specified by:
isConnectedin interfaceFileTransferClientInterface- Returns:
- true if connected, false otherwise
-
getInitialRemoteDirectory
Returns the initial remote directory that all connections change to immediately on connection.- Returns:
- Returns the remote host.
-
setInitialRemoteDirectory
Set the initial remote directory that all connections change to immediately on connection. This may only be done if the client is not already connected to the server.- Parameters:
directory- The initial remote directory- Throws:
FTPException- Thrown if the client is already connected to the server.
-
getRemoteDirectory
Get the current remote directory of the master context. Note that individual connections may have different current directories.- Specified by:
getRemoteDirectoryin interfaceFileTransferClientInterface- Returns:
- current remote directory of master context
-
setEventListener
Set the event listener for transfer event notification- Specified by:
setEventListenerin interfaceFileTransferClientInterface- Parameters:
listener- event listener reference
-
getStatistics
Get statistics on file transfers and deletions.- Specified by:
getStatisticsin interfaceFileTransferClientInterface- Returns:
- FTPStatistics
-
connect
Make a connection to the FTP server. A number of connections are made - that number being equal to the size of the FTP connection pool.- Specified by:
connectin interfaceFileTransferClientInterface- Throws:
FTPExceptionIOException
-
executeCommand
Request that the remote server execute the literal command supplied. In FTP and FTPS, this might be a SITE command, while in SFTP it might be a shell command. For example, "SITE DCB LRECL=600 RECFM=FB WRAPRECORD" might be a SITE command sent to a z/OS FTP server to set certain transfer parameters.It is up to the user to send a sensible command.
- Specified by:
executeCommandin interfaceFileTransferClientInterface- Parameters:
command- command string- Returns:
- result string by server
- Throws:
FTPExceptionIOException
-
getLastReply
Gets the last FTP reply from the server, whether valid or not. This may be null if the protocol is SFTP, which doesn't have reply objects.- Returns:
- reply object encapsulating last server response
-
getSystemType
Get a string that represents the remote system that the client is logged into.- Specified by:
getSystemTypein interfaceFileTransferClientInterface- Returns:
- system string
- Throws:
FTPExceptionIOException
-
directoryNameList
List the names of files and directories in the current directory on the FTP server.- Specified by:
directoryNameListin interfaceFileTransferClientInterface- Returns:
- String[]
- Throws:
FTPExceptionIOException
-
directoryNameList
public String[] directoryNameList(String directoryName, boolean isLongListing) throws FTPException, IOException List a directory on the FTP server.- Specified by:
directoryNameListin interfaceFileTransferClientInterface- Parameters:
directoryName- name of the directory (generally not a path)isLongListing- true if the listing is a long format listing- Returns:
- String[]
- Throws:
FTPExceptionIOException
-
directoryList
List the current directory on the FTP server.- Specified by:
directoryListin interfaceFileTransferClientInterface- Throws:
ParseExceptionFTPExceptionIOException
-
directoryList
public void directoryList(String directoryName, DirectoryListCallback lister) throws FTPException, IOException List a directory on the FTP server, calling the user-supplied callback for each entry. Listings can be interrupted while they're in progress by throwing an exception from inside the callback.- Specified by:
directoryListin interfaceFileTransferClientInterface- Parameters:
directoryName- name of the directory (generally not a path)- Throws:
FTPExceptionIOException
-
directoryList
List a directory on the FTP server.- Specified by:
directoryListin interfaceFileTransferClientInterface- Parameters:
directoryName- name of the directory (generally not a path)- Throws:
FTPExceptionIOException
-
downloadByteArray
Download a file from the FTP server into a byte array.- Specified by:
downloadByteArrayin interfaceFileTransferClientInterface- Parameters:
remoteFileName- name of the remote file to be downloaded- Throws:
FTPExceptionIOException
-
downloadFile
public void downloadFile(String localFileName, String remoteFileName) throws FTPException, IOException Download a file from the FTP server .- Specified by:
downloadFilein interfaceFileTransferClientInterface- Parameters:
localFileName- name (or full path) of the local file to be downloaded toremoteFileName- name of the remote file to be downloaded- Throws:
FTPExceptionIOException
-
downloadFile
public void downloadFile(String localFileName, String remoteFileName, WriteMode writeMode) throws FTPException, IOException Download a file from the FTP server .- Specified by:
downloadFilein interfaceFileTransferClientInterface- Parameters:
localFileName- name (or full path) of the local file to be downloaded toremoteFileName- name of the remote file to be downloadedwriteMode- mode in which the file is written to the client machine- Throws:
FTPExceptionIOException
-
downloadStream
public FileTransferInputStream downloadStream(String remoteFileName) throws FTPException, IOException Download a file from the FTP server as a stream. The close() method *must* be called on the stream once the stream has been read.- Specified by:
downloadStreamin interfaceFileTransferClientInterface- Parameters:
remoteFileName- name of the remote file to be downloaded- Returns:
- InputStream
- Throws:
FTPExceptionIOException
-
downloadURLStream
public static FileTransferInputStream downloadURLStream(String ftpURL) throws MalformedURLException, IOException, FTPException Open an InputStream for the given FTP URL. The URL must be of the form(protocol)://[user[:password]@]host[:port]/path. The value of 'protocol' may be ftp for plain FTP; sftp for SFTP; ftps, ftpes or ftpse for explicit FTPS; or ftpis or ftpsi for implicit FTPS. The stream should be closed when the transfer is complete.- Parameters:
ftpURL- The URL must be of the form(protocol)://[user[:password]@]host[:port]/path.- Returns:
- FileTransferInputStream for the given URL. The stream should be closed when the transfer is complete.
- Throws:
MalformedURLException- Thrown when an invalid URL is provided.IOException- Thrown when an I/O-related error occurs.FTPException- Thrown when an FTP-protocol-related error occurs.
-
downloadURLFile
public static void downloadURLFile(String localFileName, String ftpURL) throws MalformedURLException, IOException, FTPException Downloads the given file to the given FTP URL. The URL must be of the form(protocol)://[user[:password]@]host[:port]/path. The value of 'protocol' may be ftp for plain FTP; sftp for SFTP; ftps, ftpes or ftpse for explicit FTPS; or ftpis or ftpsi for implicit FTPS.- Parameters:
localFileName- Path to local fileftpURL- The URL must be of the form(protocol)://[user[:password]@]host[:port]/path.- Throws:
MalformedURLException- Thrown when an invalid URL is provided.IOException- Thrown when an I/O-related error occurs.FTPException- Thrown when an FTP-protocol-related error occurs.
-
uploadFile
public String uploadFile(String localFileName, String remoteFileName) throws FTPException, IOException Upload a file to the FTP server. If a null is supplied as the remoteFileName, the STOU (store unique) FTP feature will be used (if available) and the FTP server will generate a unique name for the file.- Specified by:
uploadFilein interfaceFileTransferClientInterface- Parameters:
localFileName- name (or full path) of the local file to be downloaded toremoteFileName- name of the remote file to be downloaded (or null to generate a unique name)- Returns:
- name of remote file
- Throws:
FTPExceptionIOException
-
uploadFile
public String uploadFile(String localFileName, String remoteFileName, WriteMode writeMode) throws FTPException, IOException Upload a file to the FTP server. If a null is supplied as the remoteFileName, the STOU (store unique) FTP feature will be used (if available) and the FTP server will generate a unique name for the file.- Specified by:
uploadFilein interfaceFileTransferClientInterface- Parameters:
localFileName- name (or full path) of the local file to be downloaded toremoteFileName- name of the remote file to be downloaded (or null to generate a unique name)writeMode- mode to write to the remote file with- Returns:
- name of remote file
- Throws:
FTPExceptionIOException
-
uploadByteArray
public String uploadByteArray(byte[] bytes, String remoteFileName, WriteMode writeMode) throws FTPException, IOException Upload a byte array to the FTP server. If a null is supplied as the remoteFileName, the STOU (store unique) FTP feature will be used (if available) and the FTP server will generate a unique name for the file.- Parameters:
bytes- byte array to uploadremoteFileName- name of the remote filewriteMode- mode in which the file is written to the servercallback- callback to be notified when upload is completedtag- any object reference can be saved in this tag and can be accessed later from the result object (e.g. in the callback).- Returns:
- name of remote file
- Throws:
FTPExceptionIOException
-
uploadStream
Upload a file to the FTP server by writing to a stream. The close() method *must* be called on the stream once the stream has been read. If a null is supplied as the remoteFileName, the STOU (store unique) FTP feature will be used (if available) and the FTP server will generate a unique name for the file. This name can be obtained afterwards from- Specified by:
uploadStreamin interfaceFileTransferClientInterface- Parameters:
remoteFileName- name of the remote file to be uploaded- Returns:
- FTPOutputStream
- Throws:
FTPException
-
uploadStream
public FileTransferOutputStream uploadStream(String remoteFileName, WriteMode writeMode) throws FTPException Upload a file to the FTP server by writing to a stream. The close() method *must* be called on the stream once the stream has been read. If a null is supplied as the remoteFileName, the STOU (store unique) FTP feature will be used (if available) and the FTP server will generate a unique name for the file. This name can be obtained afterwards from- Specified by:
uploadStreamin interfaceFileTransferClientInterface- Parameters:
remoteFileName- name of the remote file to be uploadedwriteMode- mode in which the file is written to the server- Returns:
- FileTransferOutputStream
- Throws:
FTPException
-
uploadURLStream
public static FileTransferOutputStream uploadURLStream(String ftpURL) throws MalformedURLException, IOException, FTPException Open an OutputStream for the given FTP URL. The URL must be of the form(protocol)://[user[:password]@]host[:port]/path. The value of 'protocol' may be ftp for plain FTP; sftp for SFTP; ftps, ftpes or ftpse for explicit FTPS; or ftpis or ftpsi for implicit FTPS. The stream must be closed when the transfer is complete.- Parameters:
ftpURL- The URL must be of the form(protocol)://[user[:password]@]host[:port]/path.- Returns:
- FileTransferInputStream for the given URL. The stream should be closed when the transfer is complete.
- Throws:
MalformedURLException- Thrown when an invalid URL is provided.IOException- Thrown when an I/O-related error occurs.FTPException- Thrown when an FTP-protocol-related error occurs.
-
uploadURLFile
public static void uploadURLFile(String localFileName, String ftpURL) throws MalformedURLException, IOException, FTPException Uploads the given file to the given FTP URL. The URL must be of the form(protocol)://[user[:password]@]host[:port]/path. The value of 'protocol' may be ftp for plain FTP; sftp for SFTP; ftps, ftpes or ftpse for explicit FTPS; or ftpis or ftpsi for implicit FTPS.- Parameters:
localFileName- Path to local fileftpURL- The URL must be of the form(protocol)://[user[:password]@]host[:port]/path.- Throws:
MalformedURLException- Thrown when an invalid URL is provided.IOException- Thrown when an I/O-related error occurs.FTPException- Thrown when an FTP-protocol-related error occurs.
-
getSize
Get the size of a remote file.- Specified by:
getSizein interfaceFileTransferClientInterface- Parameters:
remoteFileName- name of remote file- Returns:
- long
- Throws:
FTPExceptionIOException
-
getModifiedTime
Get the modified-time of a remote file.- Specified by:
getModifiedTimein interfaceFileTransferClientInterface- Parameters:
remoteFileName- name of remote file- Returns:
- Date
- Throws:
FTPExceptionIOException
-
setModifiedTime
public void setModifiedTime(String remoteFileName, Date modifiedTime) throws FTPException, IOException Set the modified-time of a remote file. May not be supported by all servers.- Specified by:
setModifiedTimein interfaceFileTransferClientInterface- Parameters:
remoteFileName- name of remote filemodifiedTime- new modified time- Throws:
FTPExceptionIOException
-
setPermissions
Set the permissions of the supplied file or directory. Only supported in SFTP.Absolute modes are octal numbers specifying the complete list of attributes for the files; you specify attributes by OR'ing together these bits. These must be octal numbers, and are listed below.
For example, for individual read, write and execute only, 0700 should be supplied (0400 | 0200 | 0100).0400 Individual read 0200 Individual write 0100 Individual execute (or list directory) 0040 Group read 0020 Group write 0010 Group execute 0004 Other read 0002 Other write 0001 Other execute
- Parameters:
remotePath- path of file or directorypermissions- octal permissions (must be preceded with a '0').- Throws:
FTPExceptionIOException
-
exists
Determine if a remote file exists.- Specified by:
existsin interfaceFileTransferClientInterface- Parameters:
remoteFileName- name of remote file- Throws:
FTPExceptionIOException
-
existsDirectory
Determine if a remote directory exists.- Parameters:
remoteDir- name of remote directory- Throws:
FTPExceptionIOException
-
deleteFile
Deletes a remote file.- Specified by:
deleteFilein interfaceFileTransferClientInterface- Parameters:
remoteFileName- name of remote file- Throws:
FTPExceptionIOException
-
deleteMultipleFiles
Deletes remote files in the current directory that match the supplied wildcard- Parameters:
wildcard- wildcard string (supporting '*' and '?')- Throws:
FTPExceptionIOException
-
deleteMultipleFiles
Deletes remote files in the current directory that match the supplied filename filter- Parameters:
wildcard- filename filter- Throws:
FTPExceptionIOException
-
deleteMultipleFiles
public void deleteMultipleFiles(String remoteDirectory, String wildcard, boolean recursive) throws FTPException, IOException Deletes remote files in the current directory.- Parameters:
remoteFileName- name of remote file- Throws:
FTPExceptionIOException
-
deleteMultipleFiles
public void deleteMultipleFiles(String remoteDirectory, FileFilter filter, boolean recursive) throws FTPException, IOException Deletes remote files in the current directory.- Parameters:
remoteFileName- name of remote file- Throws:
FTPExceptionIOException
-
rename
Rename a remote file or directory.- Specified by:
renamein interfaceFileTransferClientInterface- Parameters:
renameFromName- original namerenameToName- new name- Throws:
FTPExceptionIOException
-
changeDirectory
Change directory on the FTP server.- Specified by:
changeDirectoryin interfaceFileTransferClientInterface- Parameters:
directoryName- name the remote directory to change into- Throws:
FTPExceptionIOException
-
changeToParentDirectory
Change to parent directory on the FTP server.- Specified by:
changeToParentDirectoryin interfaceFileTransferClientInterface- Parameters:
directoryName- name the remote directory to change into- Throws:
FTPExceptionIOException
-
createDirectory
Create directory on the FTP server.- Specified by:
createDirectoryin interfaceFileTransferClientInterface- Parameters:
directoryName- name the remote directory to create- Throws:
FTPExceptionIOException
-
deleteDirectory
Delete a directory on the FTP server. The directory must be empty, and not the current directory.- Specified by:
deleteDirectoryin interfaceFileTransferClientInterface- Parameters:
directoryName- name the remote directory to create- Throws:
FTPExceptionIOException
-
deleteDirectory
public void deleteDirectory(String directoryName, boolean recursive) throws FTPException, IOException Delete a directory on the FTP server, and optionally sub-directories. The directory must not be the current directory. The directory must be empty for a non-recursive delete.- Parameters:
directoryName- name the remote directory to createrecursive- true if recursive delete- Throws:
FTPExceptionIOException
-
uploadMultiple
Uploads local files from the supplied local directory that match the supplied FileFilter into the current remote directory. Not recursive. Operation is synchronous.- Parameters:
localDir- name of local directoryfilter- filename filter- Throws:
FTPExceptionIOException
-
uploadMultiple
Uploads local files from the supplied local directory that match the supplied wildcard into the current remote directory. Not recursive. Operation is synchronous.- Parameters:
localDir- name of local directorywildcard- wildcard filter for files to be uploaded (supports '*' and '?')- Throws:
FTPExceptionIOException
-
uploadMultiple
public void uploadMultiple(String localDir, String remoteDir, String wildcard, boolean recursive) throws FTPException, IOException Uploads local files from the supplied local directory that match the supplied wildcard into the supplied remote directory. If recursive is set to true, goes through all subdirectories. Operation is synchronous.- Parameters:
localDir- name of local directoryremoteDir- name of remote directorywildcard- wildcard filter for files to be uploaded (supports '*' and '?')recursive- if true, operation is recursive through subdirectories- Throws:
FTPExceptionIOException
-
uploadMultiple
public void uploadMultiple(String localDir, String remoteDir, FileFilter filter, boolean recursive) throws FTPException, IOException Uploads local files from the supplied local directory that match the supplied wildcard into the supplied remote directory. If recursive is set to true, goes through all sub-directories. Operation is synchronous.- Parameters:
localDir- name of local directoryremoteDir- name of remote directoryfilter- filename filter for files to be uploadedrecursive- if true, operation is recursive through sub-directories- Throws:
FTPExceptionIOException
-
downloadMultiple
Downloads remote files to the supplied local directory that match the supplied wildcard from the current remote directory. Not recursive. Operation is asynchronous.- Parameters:
localDir- name of local directoryfilter- filename filter- Throws:
FTPExceptionIOException
-
downloadMultiple
Downloads remote files to the supplied local directory that match the supplied wildcard from the current remote directory. Not recursive. Operation is asynchronous.- Parameters:
localDir- name of local directorywildcard- wildcard filter for files to be uploaded (supports '*' and '?')- Throws:
FTPExceptionIOException
-
downloadMultiple
public void downloadMultiple(String localDir, String remoteDir, String wildcard, boolean recursive) throws FTPException, IOException Downloads remote files to the supplied local directory that match the supplied wildcard from the current remote directory. If recursive is set to true, goes through all sub-directories. Operation is synchronous.- Parameters:
localDir- name of local directoryremoteDir- name of remote directorywildcard- wildcard filter for files to be uploaded (supports '*' and '?')recursive- if true, operation is recursive through sub-directories- Throws:
FTPExceptionIOException
-
downloadMultiple
public void downloadMultiple(String localDir, String remoteDir, FileFilter filter, boolean recursive) throws FTPException, IOException Downloads remote files to the supplied local directory that match the supplied FileFilter from the current remote directory. If recursive is set to true, goes through all sub-directories. Operation is synchronous.- Parameters:
localDir- name of local directoryremoteDir- name of remote directoryfilter- filename filter for files to be uploadedrecursive- if true, operation is recursive through sub-directories- Throws:
FTPExceptionIOException
-
disconnect
Disconnect from the FTP server. All connections in the FTP connection pool are disconnected.- Specified by:
disconnectin interfaceFileTransferClientInterface- Throws:
FTPExceptionIOException
-
disconnect
Disconnect from the FTP server immediately.- Specified by:
disconnectin interfaceFileTransferClientInterface- Throws:
FTPExceptionIOException
-
addErrorListener
Add an error listener to the list of listeners- Parameters:
listener- new error listener
-
shutdown
protected void shutdown(boolean immediate) Shutdown all the worker threads in the task processor.- Parameters:
immediate- if true, shutdown immediately, i.e. do not wait for worker threads to terminate
-
finalize
public void finalize()Finalize this instance by shutting down its threads -
cancelAllTransfers
public void cancelAllTransfers()Cancel all transfers that are either pending or currently under way- Specified by:
cancelAllTransfersin interfaceFileTransferClientInterface
-