|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.enterprisedt.net.ftp.SecureFileTransferClient
public class SecureFileTransferClient
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.
| Field Summary | |
|---|---|
protected java.util.HashMap |
activeTransferTasks
Active transfer tasks, hashed on id |
protected AdvancedFTPSettings |
advancedFTPSettings
Advanced configuration parameters that often aren't used |
protected AdvancedGeneralSettings |
advancedSettings
|
protected AdvancedSSHSettings |
advancedSSHSettings
|
protected AdvancedSSLSettings |
advancedSSLSettings
|
protected com.enterprisedt.net.ftp.async.internal.AsyncFileTransferClientImpl |
asyncImpl
|
protected EventListener |
eventListener
Notifies of various events |
protected com.enterprisedt.net.ftp.async.internal.SecureConnectionContext |
masterContext
Connection context |
protected MultipleTransferSettings |
multiSettings
|
protected FileStatistics |
statistics
|
| Constructor Summary | |
|---|---|
SecureFileTransferClient()
Constructor. |
|
SecureFileTransferClient(int initialPoolSize,
int maxPoolSize)
Constructor. |
|
| Method Summary | |
|---|---|
void |
addErrorListener(ErrorListener listener)
Add an error listener to the list of listeners |
void |
cancelAllTransfers()
Cancel all transfers that are either pending or currently under way |
void |
changeDirectory(java.lang.String directoryName)
Change directory on the FTP server. |
void |
changeToParentDirectory()
Change to parent directory on the FTP server. |
protected void |
checkConnection(boolean shouldBeConnected)
Checks if the client has connected to the server and throws an exception if it hasn't. |
void |
connect()
Make a connection to the FTP server. |
void |
createDirectory(java.lang.String directoryName)
Create directory on the FTP server. |
void |
deleteDirectory(java.lang.String directoryName)
Delete a directory on the FTP server. |
void |
deleteDirectory(java.lang.String directoryName,
boolean recursive)
Delete a directory on the FTP server, and optionally sub-directories. |
void |
deleteFile(java.lang.String remoteFileName)
Deletes a remote file. |
void |
deleteMultipleFiles(java.io.FileFilter filter)
Deletes remote files in the current directory that match the supplied filename filter |
void |
deleteMultipleFiles(java.lang.String wildcard)
Deletes remote files in the current directory that match the supplied wildcard |
void |
deleteMultipleFiles(java.lang.String remoteDirectory,
java.io.FileFilter filter,
boolean recursive)
Deletes remote files in the current directory. |
void |
deleteMultipleFiles(java.lang.String remoteDirectory,
java.lang.String wildcard,
boolean recursive)
Deletes remote files in the current directory. |
FTPFile[] |
directoryList()
List the current directory on the FTP server. |
FTPFile[] |
directoryList(java.lang.String directoryName)
List a directory on the FTP server. |
java.lang.String[] |
directoryNameList()
List the names of files and directories in the current directory on the FTP server. |
java.lang.String[] |
directoryNameList(java.lang.String directoryName,
boolean isLongListing)
List a directory on the FTP server. |
void |
disconnect()
Disconnect from the FTP server. |
void |
disconnect(boolean immediate)
Disconnect from the FTP server immediately. |
byte[] |
downloadByteArray(java.lang.String remoteFileName)
Download a file from the FTP server into a byte array. |
void |
downloadFile(java.lang.String localFileName,
java.lang.String remoteFileName)
Download a file from the FTP server . |
void |
downloadFile(java.lang.String localFileName,
java.lang.String remoteFileName,
WriteMode writeMode)
Download a file from the FTP server . |
void |
downloadMultiple(java.lang.String localDir,
java.io.FileFilter filter)
Downloads remote files to the supplied local directory that match the supplied wildcard from the current remote directory. |
void |
downloadMultiple(java.lang.String localDir,
java.lang.String wildcard)
Downloads remote files to the supplied local directory that match the supplied wildcard from the current remote directory. |
void |
downloadMultiple(java.lang.String localDir,
java.lang.String remoteDir,
java.io.FileFilter filter,
boolean recursive)
Downloads remote files to the supplied local directory that match the supplied FileFilter from the current remote directory. |
void |
downloadMultiple(java.lang.String localDir,
java.lang.String remoteDir,
java.lang.String wildcard,
boolean recursive)
Downloads remote files to the supplied local directory that match the supplied wildcard from the current remote directory. |
FileTransferInputStream |
downloadStream(java.lang.String remoteFileName)
Download a file from the FTP server as a stream. |
java.lang.String |
executeCommand(java.lang.String command)
Request that the remote server execute the literal command supplied. |
boolean |
exists(java.lang.String remoteFileName)
Determine if a remote file exists. |
void |
finalize()
Finalize this instance by shutting down its threads |
AdvancedFTPSettings |
getAdvancedFTPSettings()
Get the advanced FTP configuration parameters object |
AdvancedGeneralSettings |
getAdvancedSettings()
Get the advanced general configuration parameters object, for none protocol specific parameters |
AdvancedSSHSettings |
getAdvancedSSHSettings()
Get the advanced SSH configuration parameters object |
AdvancedSSLSettings |
getAdvancedSSLSettings()
Get the advanced SSL configuration parameters object |
FTPTransferType |
getContentType()
Get the current content type for all connections. |
java.lang.String |
getInitialRemoteDirectory()
Returns the initial remote directory that all connections change to immediately on connection. |
java.util.Date |
getModifiedTime(java.lang.String remoteFileName)
Get the modified-time of a remote file. |
MultipleTransferSettings |
getMultipleTransferSettings()
Get the configuration object that controls the settings used for multiple transfers |
java.lang.String |
getPassword()
Get the current user password. |
Protocol |
getProtocol()
Get the current protocol being used |
java.lang.String |
getRemoteDirectory()
Get the current remote directory of the master context. |
java.lang.String |
getRemoteHost()
Returns the IP address or name of the remote host. |
int |
getRemotePort()
Returns the port being connected to on the remote server. |
long |
getSize(java.lang.String remoteFileName)
Get the size of a remote file. |
FileStatistics |
getStatistics()
Get statistics on file transfers and deletions. |
java.lang.String |
getSystemType()
Get a string that represents the remote system that the client is logged into. |
int |
getTimeout()
Returns the timeout for socket connections. |
java.lang.String |
getUserName()
Get the current user name. |
boolean |
isConnected()
Is this client currently connected to the server? |
boolean |
isDetectContentType()
Get the detect content type flag |
boolean |
isServerValidationEnabled()
Is server validation switched on, i.e. |
void |
loadSSHServerValidation(java.lang.String knownHosts)
Load the public keys that the server public key will be validated against. |
void |
loadSSLServerValidation(java.lang.String rootCertificatesPath)
Load the root certificates that the server certificate will be validated against. |
void |
rename(java.lang.String renameFromName,
java.lang.String renameToName)
Rename a remote file or directory. |
void |
setContentType(FTPTransferType type)
Set the transfer type for all connections, either ASCII or binary. |
void |
setDetectContentType(boolean detectContentType)
Set auto detect of filetypes on or off. |
void |
setEventListener(EventListener listener)
Set the event listener for transfer event notification |
void |
setInitialRemoteDirectory(java.lang.String directory)
Set the initial remote directory that all connections change to immediately on connection. |
void |
setModifiedTime(java.lang.String remoteFileName,
java.util.Date modifiedTime)
Set the modified-time of a remote file. |
void |
setPassword(java.lang.String password)
Set the password of the user to log in with. |
void |
setProtocol(Protocol protocol)
Set the current protocol to be used. |
void |
setRemoteHost(java.lang.String remoteHost)
Set the IP address or name of the remote host This may only be done if the client is not already connected to the server. |
void |
setRemotePort(int remotePort)
Set the port to connect to on the remote server. |
void |
setServerValidationEnabled(boolean enabled)
Change the server validation setting, switching it on or off. |
void |
setTimeout(int timeout)
Set the timeout for socket connections. |
void |
setUserName(java.lang.String userName)
Set the name of the user to log in with. |
protected void |
shutdown(boolean immediate)
Shutdown all the worker threads in the task processor. |
java.lang.String |
uploadByteArray(byte[] bytes,
java.lang.String remoteFileName,
WriteMode writeMode)
Upload a byte array to the FTP server. |
java.lang.String |
uploadFile(java.lang.String localFileName,
java.lang.String remoteFileName)
Upload a file to the FTP server. |
java.lang.String |
uploadFile(java.lang.String localFileName,
java.lang.String remoteFileName,
WriteMode writeMode)
Upload a file to the FTP server. |
void |
uploadMultiple(java.lang.String localDir,
java.io.FileFilter filter)
Uploads local files from the supplied local directory that match the supplied FileFilter into the current remote directory. |
void |
uploadMultiple(java.lang.String localDir,
java.lang.String wildcard)
Uploads local files from the supplied local directory that match the supplied wildcard into the current remote directory. |
void |
uploadMultiple(java.lang.String localDir,
java.lang.String remoteDir,
java.io.FileFilter filter,
boolean recursive)
Uploads local files from the supplied local directory that match the supplied wildcard into the supplied remote directory. |
void |
uploadMultiple(java.lang.String localDir,
java.lang.String remoteDir,
java.lang.String wildcard,
boolean recursive)
Uploads local files from the supplied local directory that match the supplied wildcard into the supplied remote directory. |
FileTransferOutputStream |
uploadStream(java.lang.String remoteFileName)
Upload a file to the FTP server by writing to a stream. |
FileTransferOutputStream |
uploadStream(java.lang.String remoteFileName,
WriteMode writeMode)
Upload a file to the FTP server by writing to a stream. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected com.enterprisedt.net.ftp.async.internal.AsyncFileTransferClientImpl asyncImpl
protected com.enterprisedt.net.ftp.async.internal.SecureConnectionContext masterContext
protected java.util.HashMap activeTransferTasks
protected EventListener eventListener
protected MultipleTransferSettings multiSettings
protected AdvancedFTPSettings advancedFTPSettings
protected AdvancedGeneralSettings advancedSettings
protected AdvancedSSLSettings advancedSSLSettings
protected AdvancedSSHSettings advancedSSHSettings
protected FileStatistics statistics
| Constructor Detail |
|---|
public SecureFileTransferClient(int initialPoolSize,
int maxPoolSize)
initialPoolSize - initial size of connection pool (i.e. number of managed connections).maxPoolSize - maximum size of pool.public SecureFileTransferClient()
| Method Detail |
|---|
protected void checkConnection(boolean shouldBeConnected)
throws FTPException
FTPException - Thrown if the client has not connected to the server.public java.lang.String getRemoteHost()
getRemoteHost in interface FileTransferClientInterface
public void setRemoteHost(java.lang.String remoteHost)
throws FTPException
setRemoteHost in interface FileTransferClientInterfaceremoteHost - The IP address or name of the remote host
FTPException - Thrown if the client is already connected to the server.public Protocol getProtocol()
public void setProtocol(Protocol protocol)
throws FTPException
protocol - protocol to use
FTPExceptionpublic int getTimeout()
getTimeout in interface FileTransferClientInterface
public void setTimeout(int timeout)
throws FTPException
setTimeout in interface FileTransferClientInterfacetimeout - the timeout to use in milliseconds
FTPException - Thrown if the client is already connected to the server.public int getRemotePort()
getRemotePort in interface FileTransferClientInterface
public void setRemotePort(int remotePort)
throws FTPException
setRemotePort in interface FileTransferClientInterfaceremotePort - The port to use.
FTPException - Thrown if the client is already connected to the server.
public void setContentType(FTPTransferType type)
throws java.io.IOException,
FTPException
setContentType in interface FileTransferClientInterfacetype - transfer type
FTPException
java.io.IOException
FTPExceptionpublic FTPTransferType getContentType()
getContentType in interface FileTransferClientInterfacepublic void setDetectContentType(boolean detectContentType)
setDetectContentType in interface FileTransferClientInterfacedetectContentType - true if detecting content type, false if notpublic boolean isDetectContentType()
isDetectContentType in interface FileTransferClientInterface
public void setUserName(java.lang.String userName)
throws FTPException
setUserName in interface FileTransferClientInterfaceuserName - user-name to log in with.
FTPExceptionpublic java.lang.String getPassword()
getPassword in interface FileTransferClientInterface
public void setPassword(java.lang.String password)
throws FTPException
setPassword in interface FileTransferClientInterfacepassword - password to log in with.
FTPExceptionpublic java.lang.String getUserName()
getUserName in interface FileTransferClientInterfacepublic AdvancedFTPSettings getAdvancedFTPSettings()
getAdvancedFTPSettings in interface FileTransferClientInterfacepublic AdvancedGeneralSettings getAdvancedSettings()
getAdvancedSettings in interface FileTransferClientInterfacepublic AdvancedSSLSettings getAdvancedSSLSettings()
public AdvancedSSHSettings getAdvancedSSHSettings()
public MultipleTransferSettings getMultipleTransferSettings()
public boolean isServerValidationEnabled()
public void setServerValidationEnabled(boolean enabled)
throws FTPException
enabled - true to enable, false to disable
FTPException
public void loadSSLServerValidation(java.lang.String rootCertificatesPath)
throws java.io.FileNotFoundException,
java.io.IOException,
FTPException
rootCertificatesPath -
java.io.FileNotFoundException
java.io.IOException
FTPException
public void loadSSHServerValidation(java.lang.String knownHosts)
throws java.io.FileNotFoundException,
java.io.IOException,
FTPException
rootCertificatesPath -
java.io.FileNotFoundException
java.io.IOException
FTPException
FTPExceptionpublic boolean isConnected()
isConnected in interface FileTransferClientInterfacepublic java.lang.String getInitialRemoteDirectory()
public void setInitialRemoteDirectory(java.lang.String directory)
throws FTPException
directory - The initial remote directory
FTPException - Thrown if the client is already connected to the server.public java.lang.String getRemoteDirectory()
getRemoteDirectory in interface FileTransferClientInterfacepublic void setEventListener(EventListener listener)
setEventListener in interface FileTransferClientInterfacelistener - event listener referencepublic FileStatistics getStatistics()
getStatistics in interface FileTransferClientInterface
public void connect()
throws FTPException,
java.io.IOException
connect in interface FileTransferClientInterfaceFTPException
java.io.IOException
public java.lang.String executeCommand(java.lang.String command)
throws FTPException,
java.io.IOException
It is up to the user to send a sensible command.
executeCommand in interface FileTransferClientInterfacecommand - command string
FTPException
java.io.IOException
public java.lang.String getSystemType()
throws FTPException,
java.io.IOException
getSystemType in interface FileTransferClientInterfaceFTPException
java.io.IOException
public java.lang.String[] directoryNameList()
throws FTPException,
java.io.IOException
directoryNameList in interface FileTransferClientInterfaceFTPException, - IOException
FTPException
java.io.IOException
public java.lang.String[] directoryNameList(java.lang.String directoryName,
boolean isLongListing)
throws FTPException,
java.io.IOException
directoryNameList in interface FileTransferClientInterfacedirectoryName - name of the directory (generally not a path)isLongListing - true if the listing is a long format listing
FTPException, - IOException
FTPException
java.io.IOException
public FTPFile[] directoryList()
throws FTPException,
java.io.IOException,
java.text.ParseException
directoryList in interface FileTransferClientInterfaceFTPException, - IOException
java.text.ParseException
FTPException
java.io.IOException
public FTPFile[] directoryList(java.lang.String directoryName)
throws FTPException,
java.io.IOException
directoryList in interface FileTransferClientInterfacedirectoryName - name of the directory (generally not a path)
FTPException, - IOException
FTPException
java.io.IOException
public byte[] downloadByteArray(java.lang.String remoteFileName)
throws FTPException,
java.io.IOException
downloadByteArray in interface FileTransferClientInterfaceremoteFileName - name of the remote file to be downloaded
FTPException
java.io.IOException
public void downloadFile(java.lang.String localFileName,
java.lang.String remoteFileName)
throws FTPException,
java.io.IOException
downloadFile in interface FileTransferClientInterfacelocalFileName - name (or full path) of the local file to be downloaded toremoteFileName - name of the remote file to be downloaded
FTPException
java.io.IOException
public void downloadFile(java.lang.String localFileName,
java.lang.String remoteFileName,
WriteMode writeMode)
throws FTPException,
java.io.IOException
downloadFile in interface FileTransferClientInterfacelocalFileName - 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
FTPException
java.io.IOException
public FileTransferInputStream downloadStream(java.lang.String remoteFileName)
throws FTPException,
java.io.IOException
downloadStream in interface FileTransferClientInterfaceremoteFileName - name of the remote file to be downloaded
FTPException
java.io.IOException
public java.lang.String uploadFile(java.lang.String localFileName,
java.lang.String remoteFileName)
throws FTPException,
java.io.IOException
uploadFile in interface FileTransferClientInterfacelocalFileName - 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)append - true if in append mode
FTPException
java.io.IOException
public java.lang.String uploadFile(java.lang.String localFileName,
java.lang.String remoteFileName,
WriteMode writeMode)
throws FTPException,
java.io.IOException
uploadFile in interface FileTransferClientInterfacelocalFileName - 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
FTPException
java.io.IOException
public java.lang.String uploadByteArray(byte[] bytes,
java.lang.String remoteFileName,
WriteMode writeMode)
throws FTPException,
java.io.IOException
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).
FTPException
java.io.IOException
public FileTransferOutputStream uploadStream(java.lang.String remoteFileName)
throws FTPException
FileTransferOutputStream#getRemoteFileName()
uploadStream in interface FileTransferClientInterfaceremoteFileName - name of the remote file to be uploaded
FTPException
public FileTransferOutputStream uploadStream(java.lang.String remoteFileName,
WriteMode writeMode)
throws FTPException
FileTransferOutputStream#getRemoteFileName()
uploadStream in interface FileTransferClientInterfaceremoteFileName - name of the remote file to be uploadedwriteMode - mode in which the file is written to the server
FTPException
public long getSize(java.lang.String remoteFileName)
throws FTPException,
java.io.IOException
getSize in interface FileTransferClientInterfaceremoteFileName - name of remote file
FTPException
java.io.IOException
public java.util.Date getModifiedTime(java.lang.String remoteFileName)
throws FTPException,
java.io.IOException
getModifiedTime in interface FileTransferClientInterfaceremoteFileName - name of remote file
FTPException
java.io.IOException
public void setModifiedTime(java.lang.String remoteFileName,
java.util.Date modifiedTime)
throws FTPException,
java.io.IOException
setModifiedTime in interface FileTransferClientInterfaceremoteFileName - name of remote filemodifiedTime - new modified time
FTPException
java.io.IOException
public boolean exists(java.lang.String remoteFileName)
throws FTPException,
java.io.IOException
exists in interface FileTransferClientInterfaceremoteFileName - name of remote file
FTPException
java.io.IOException
public void deleteFile(java.lang.String remoteFileName)
throws FTPException,
java.io.IOException
deleteFile in interface FileTransferClientInterfaceremoteFileName - name of remote file
FTPException
java.io.IOException
public void deleteMultipleFiles(java.lang.String wildcard)
throws FTPException,
java.io.IOException
wildcard - wildcard string (supporting '*' and '?')
FTPException
java.io.IOException
public void deleteMultipleFiles(java.io.FileFilter filter)
throws FTPException,
java.io.IOException
wildcard - filename filter
FTPException
java.io.IOException
public void deleteMultipleFiles(java.lang.String remoteDirectory,
java.lang.String wildcard,
boolean recursive)
throws FTPException,
java.io.IOException
remoteFileName - name of remote file
FTPException
java.io.IOException
public void deleteMultipleFiles(java.lang.String remoteDirectory,
java.io.FileFilter filter,
boolean recursive)
throws FTPException,
java.io.IOException
remoteFileName - name of remote file
FTPException
java.io.IOException
public void rename(java.lang.String renameFromName,
java.lang.String renameToName)
throws FTPException,
java.io.IOException
rename in interface FileTransferClientInterfacerenameFromName - original namerenameToName - new name
FTPException, - IOException
FTPException
java.io.IOException
public void changeDirectory(java.lang.String directoryName)
throws FTPException,
java.io.IOException
changeDirectory in interface FileTransferClientInterfacedirectoryName - name the remote directory to change into
FTPException, - IOException
FTPException
java.io.IOException
public void changeToParentDirectory()
throws FTPException,
java.io.IOException
changeToParentDirectory in interface FileTransferClientInterfacedirectoryName - name the remote directory to change into
FTPException, - IOException
FTPException
java.io.IOException
public void createDirectory(java.lang.String directoryName)
throws FTPException,
java.io.IOException
createDirectory in interface FileTransferClientInterfacedirectoryName - name the remote directory to create
FTPException, - IOException
FTPException
java.io.IOException
public void deleteDirectory(java.lang.String directoryName)
throws FTPException,
java.io.IOException
deleteDirectory in interface FileTransferClientInterfacedirectoryName - name the remote directory to create
FTPException, - IOException
FTPException
java.io.IOException
public void deleteDirectory(java.lang.String directoryName,
boolean recursive)
throws FTPException,
java.io.IOException
directoryName - name the remote directory to createrecursive - true if recursive delete
FTPException, - IOException
FTPException
java.io.IOException
public void uploadMultiple(java.lang.String localDir,
java.io.FileFilter filter)
throws FTPException,
java.io.IOException
localDir - name of local directoryfilter - filename filter
FTPException
java.io.IOException
public void uploadMultiple(java.lang.String localDir,
java.lang.String wildcard)
throws FTPException,
java.io.IOException
localDir - name of local directorywildcard - wildcard filter for files to be uploaded (supports '*' and '?')
FTPException
java.io.IOException
public void uploadMultiple(java.lang.String localDir,
java.lang.String remoteDir,
java.lang.String wildcard,
boolean recursive)
throws FTPException,
java.io.IOException
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
FTPException
java.io.IOException
public void uploadMultiple(java.lang.String localDir,
java.lang.String remoteDir,
java.io.FileFilter filter,
boolean recursive)
throws FTPException,
java.io.IOException
localDir - name of local directoryremoteDir - name of remote directoryfilter - filename filter for files to be uploadedrecursive - if true, operation is recursive through sub-directories
FTPException
java.io.IOException
public void downloadMultiple(java.lang.String localDir,
java.io.FileFilter filter)
throws FTPException,
java.io.IOException
localDir - name of local directoryfilter - filename filter
FTPException
java.io.IOException
public void downloadMultiple(java.lang.String localDir,
java.lang.String wildcard)
throws FTPException,
java.io.IOException
localDir - name of local directorywildcard - wildcard filter for files to be uploaded (supports '*' and '?')
FTPException
java.io.IOException
public void downloadMultiple(java.lang.String localDir,
java.lang.String remoteDir,
java.lang.String wildcard,
boolean recursive)
throws FTPException,
java.io.IOException