public class FileTransferProtocolClient extends Object implements FileTransferProtocol
This class provides the basic functionality of an FTP client based on
Apache's commons-net library. Some of the basic functionality is wrapped to
provide FileTransferProtocolClient specific exceptions, or to
provide the functionality required by a framework component.
| Constructor and Description |
|---|
FileTransferProtocolClient(boolean active,
String remoteHostname,
String localHost,
Integer maxRetryAttempts,
String password,
Integer remotePort,
String username,
String systemKey,
Integer connectionTimeout,
Integer soTimeout,
Integer dataTimeout)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
cd(String targetPath) |
void |
connect()
Connect to the FTP server
|
void |
deleteRemoteDirectory(String directoryPath,
boolean recurse) |
void |
deleteRemoteFile(String filename) |
void |
disconnect()
Disconnect
|
void |
echoConfig()
Method used to log the configuration information used to initialise the
client.
|
void |
ensureConnection() |
BaseFileTransferMappedRecord |
get(ClientListEntry clientListEntry) |
BaseFileTransferMappedRecord |
get(String filePath) |
void |
get(String filePath,
OutputStream outputStream)
OutputStream is closed by the caller
|
void |
get(String filePath,
OutputStream outputStream,
int resume,
long offset) |
InputStream |
getAsInputStream(String filePath) |
InputStream |
getContentAsStream(ClientListEntry entry) |
boolean |
isConnected()
Method that tests if the underlying library is valid and connected.
|
void |
login()
login to the FTP server
|
List<ClientListEntry> |
ls(String path)
Method used to get a list of all files and directories in the target path
including the "." and ".." directories.
|
void |
mkdir(String newPath)
Utility method for
mkdir(String newDirPath, boolean force)
that defaults the force parameter to true. |
void |
put(String name,
byte[] content) |
void |
putWithOutputStream(String fileName,
InputStream inputStream)
FTP Put using an output stream form an input stream.
|
String |
pwd() |
void |
rename(String currentPath,
String newPath) |
void |
validateConstructorArgs()
All constructor arguments are essential, so use this method to validate
them before attempting connection
|
public FileTransferProtocolClient(boolean active,
String remoteHostname,
String localHost,
Integer maxRetryAttempts,
String password,
Integer remotePort,
String username,
String systemKey,
Integer connectionTimeout,
Integer soTimeout,
Integer dataTimeout)
active - Whether we are active or passive moderemoteHostname - The remote hostnamelocalHost - the local hostmaxRetryAttempts - The maximum amount of retriespassword - The password to connect withremotePort - The remote port to connect tousername - The usernamesystemKey - The system keyconnectionTimeout - connection timeoutsoTimeout - Socket timeout in ms after getting a connectiondataTimeout - Data connection timeout in ms after opening a socketpublic void validateConstructorArgs()
throws ClientInitialisationException
validateConstructorArgs in interface FileTransferProtocolClientInitialisationException - if any of the required parameters
are invalidpublic void connect()
throws ClientConnectionException
connect in interface FileTransferProtocolClientConnectionException - Exception thrown when we can't connectpublic void login()
throws ClientConnectionException
login in interface FileTransferProtocolClientConnectionException - Exception thrown when we can't connectpublic boolean isConnected()
isConnected in interface FileTransferProtocoltrue if fully connected, false
otherwisepublic void disconnect()
disconnect in interface FileTransferClientpublic void echoConfig()
echoConfig in interface FileTransferProtocollogLevel - The log level at which to log the informationpublic void ensureConnection()
throws javax.resource.ResourceException
ensureConnection in interface TransactionalResourcejavax.resource.ResourceExceptionpublic void cd(String targetPath) throws ClientCommandCdException
cd in interface FileTransferClientClientCommandCdExceptionpublic void deleteRemoteDirectory(String directoryPath, boolean recurse) throws ClientException, ClientCommandLsException
deleteRemoteDirectory in interface FileTransferClientClientExceptionClientCommandLsExceptionpublic void deleteRemoteFile(String filename) throws ClientException
deleteRemoteFile in interface FileTransferClientClientExceptionpublic BaseFileTransferMappedRecord get(ClientListEntry clientListEntry) throws ClientCommandGetException
get in interface FileTransferClientClientCommandGetExceptionpublic BaseFileTransferMappedRecord get(String filePath) throws ClientCommandGetException
get in interface FileTransferClientClientCommandGetExceptionpublic void get(String filePath, OutputStream outputStream) throws ClientCommandGetException
get in interface FileTransferClientfilePath - The path to the file that we're gettingoutputStream - The stream we're getting the file withClientCommandGetException - Exception if we could not get the filepublic void get(String filePath, OutputStream outputStream, int resume, long offset) throws ClientCommandGetException
get in interface FileTransferClientClientCommandGetExceptionpublic InputStream getAsInputStream(String filePath) throws ClientCommandGetException
getAsInputStream in interface FileTransferClientClientCommandGetExceptionpublic InputStream getContentAsStream(ClientListEntry entry) throws ClientCommandGetException
getContentAsStream in interface FileTransferClientClientCommandGetExceptionpublic List<ClientListEntry> ls(String path) throws ClientCommandLsException, URISyntaxException
ls in interface FileTransferClientpath - The (directory) path to list.ClientListEntry typed ListURISyntaxException - If a malformed URI is createdClientCommandLsException - If the directory listing fails (i.e.
path not a directory or path not found)public void put(String name, byte[] content) throws ClientCommandPutException
put in interface FileTransferClientClientCommandPutExceptionpublic void putWithOutputStream(String fileName, InputStream inputStream) throws ClientCommandPutException, ClientCommandLsException, ClientCommandMkdirException
putWithOutputStream in interface FileTransferClientfileName - Name of the file we're puttinginputStream - Stream we're putting the file withClientCommandPutException - Exception if we can't putClientCommandLsException - Exception if we can't lista directoryClientCommandMkdirException - Exception if we can't make a
directorypublic String pwd() throws ClientCommandPwdException
pwd in interface FileTransferClientClientCommandPwdExceptionpublic void rename(String currentPath, String newPath) throws ClientCommandRenameException
rename in interface FileTransferClientClientCommandRenameExceptionpublic void mkdir(String newPath) throws ClientCommandMkdirException
mkdir(String newDirPath, boolean force)
that defaults the force parameter to true.mkdir in interface FileTransferClientnewPath - The new path to createClientCommandMkdirException - Exception if we can't make a
directoryCopyright © 2007-2017 Ikasan. All Rights Reserved.