com.zehon.ftps
Class FTPsClient

java.lang.Object
  extended by com.zehon.FileTransferClient
      extended by com.zehon.ftps.FTPsClient

public class FTPsClient
extends FileTransferClient

This FTPsClient class has methods for uploading/downloading files and doing remote file options such as move, copy, etc.. This class has getter/setter methods that can be injected via Spring. Log4j is used for logging, for debugging information please turn on the debug mode for this class package. Please refer to http://www.zehon.com/features_ftps.htm for more information about our FTPS.

Author:
Zehon Team (we're happy to serve you!) http://www.zehon.com/

Constructor Summary
FTPsClient()
          Empty constructor, used for Spring injection, otherwise use the other constructor.
FTPsClient(java.lang.String serverName, int port, java.lang.String username, java.lang.String password, boolean isImplicit)
          Constructor with serverName, username and password as parameters.
FTPsClient(java.lang.String serverName, int port, java.lang.String username, java.lang.String password, boolean isImplicit, java.lang.String keyStoreFilePath, java.lang.String keyStorePassword)
          Constructor with serverName, username and password, isImplicit, keyStoreFilePath and keyStorePassword as parameters.
FTPsClient(java.lang.String serverName, java.lang.String username, java.lang.String password, boolean isImplicit)
          Constructor with serverName, username and password as parameters, default standard port: 21.
FTPsClient(java.lang.String serverName, java.lang.String username, java.lang.String password, boolean isImplicit, java.lang.String keyStoreFilePath, java.lang.String keyStorePassword)
          Constructor with serverName, username and password, isImplicit, keyStoreFilePath and keyStorePassword as parameters, default standard port: 21.
 
Method Summary
 int copyFile(java.lang.String sourceFilePath, java.lang.String destFilePath)
          Copy a remote file specified by sourceFilePath to another remote folder or file path specified by destFilePath.
 int createFolder(java.lang.String nameOfFolderToCreate, java.lang.String ftpsFolder)
          Create a remote file on the ftp server specified by ftpsFolder/nameOfFolderToCreate If the folder already exists returns successfully
 int deleteFile(java.lang.String nameOfFileToDelete, java.lang.String ftpFolder)
          Delete a remote file on the ftp server specified by ftpFolder/nameOfFileToDelete
 boolean fileExists(java.lang.String ftpFolder, java.lang.String nameOfFile)
          Check if the remote ftp file exists
 boolean folderExists(java.lang.String ftpFolder)
          Check if the remote ftpFolder exists
 int getFile(java.lang.String remoteFileName, java.lang.String ftpFolder, java.lang.String toLocalFolder)
          Retrieve a remote file specified by ftpFolder/remoteFileName and buffer it and write a local folder called toLocalFolder
 java.io.InputStream getFileAsStream(java.lang.String remoteFileName, java.lang.String ftpFolder)
          Retrieve a remote file specified by ftpFolder/remoteFileName as a stream
 java.lang.String[] getFileNamesInFolder(java.lang.String ftpFolder)
          Retrieve all filenames in a remote folder specified by ftpFolder
protected  org.apache.commons.vfs.FileSystemOptions getFileSystemOptions()
           
 int getFolder(java.lang.String ftpsFolder, java.lang.String toLocalFolder, BatchTransferProgress batchTransferProgress)
          Retrieve a remote folder and all the containing filess specified by ftpsFolder recursively, write to a local folder called toLocalFolder ftpsFolder WILL NOT BE CREATED LOCALLY BUT ONLY ITS CONTENTS AND SUBDIRECTORIES REFER TO getFolderCreate if ftpsFolder needs to be created.
 int getFolder(java.lang.String ftpsFolder, java.lang.String toLocalFolder, BatchTransferProgress batchTransferProgress, boolean recursive)
          Similiar to getFolder except recursive can be switched on/off
protected  int getFolder(java.lang.String filetransferFolder, java.lang.String toLocalFolder, BatchTransferProgress batchTransferProgress, boolean justFolderContent, boolean recursive)
           
 int getFolderCreate(java.lang.String ftpsFolder, java.lang.String toLocalFolder, BatchTransferProgress batchTransferProgress)
          Similiar to getFolder except it creates ftpsFolder locally in toLocalFolder and retrieve all the containing filess specified by ftpsFolder recursively, write to a local folder called toLocalFolder
 int getFolderCreate(java.lang.String ftpsFolder, java.lang.String toLocalFolder, BatchTransferProgress batchTransferProgress, boolean recursive)
          Similiar to getFolderCreate except recursive can be switched on/off
 java.lang.String getKeyStoreFilePath()
           
 java.lang.String getKeyStorePassword()
           
 java.lang.String getPassword()
           
 int getPort()
           
protected  java.lang.String getProtocol()
           
 java.lang.String getServerName()
           
 java.lang.String getUsername()
           
 boolean isImplicit()
           
 boolean isPassive()
           
 int moveFile(java.lang.String nameOfFileToMove, java.lang.String ftpFromFolder, java.lang.String newNameOfFile, java.lang.String ftpToFolder)
          Move a remote file on the ftp server specified by ftpFromFolder/nameOfFileToMove to another remote folder with a new name specified ftpToFolder/newNameOfFile
 int sendFile(java.io.InputStream inputStream, java.lang.String nameOfFileToStore, java.lang.String ftpDestFolder)
          Take any input stream (all classes that implement from java.io.InputStream) and read it to a buffer and FTPS it to a remote FTPS Server specified by ftpDestFolder i.e / or /ftpRoot or /myftpFolder, the name of the file stored is specified by nameOfFileToStore i.e "test.txt"
 int sendFile(java.lang.String localFilePath, java.lang.String ftpDestFolder)
          Read in a file specified by localFilePath, for example: C:\myfiles\test.txt or /home/joe/images/img.jpg it does not matter if the file is of binary or text, and ftp it to a remote ftp folder specified by ftpDestFolder, i.e / or /ftpRoot or /myftpFolder.
 int sendFile(java.lang.String localFilePath, java.lang.String filetransferDestFolder, java.lang.String nameOfFileToStore)
          Similar to the other sendFile except you get to choose what name to be stored on the server
 int sendFolder(java.lang.String sendingFolder, java.lang.String ftpsFolder, BatchTransferProgress batchTransferProgress)
          Transfer all files and subdirectories recursively from sendingFolder, for example: C:\myfiles or /home/joe/images to the remote ftps folder ftpsFolder.
 int sendFolder(java.lang.String sendingFolder, java.lang.String ftpsFolder, BatchTransferProgress batchTransferProgress, boolean recursive)
          Similiar to sendFolder, only recursive can be switched on and off The progress can be monitored by registering BatchTransferProgress object with the method
protected  int sendFolder(java.lang.String sendingFolder, java.lang.String filetransferFolder, BatchTransferProgress batchTransferProgress, boolean justFolderContent, boolean recursive)
           
 int sendFolderCreate(java.lang.String sendingFolder, java.lang.String ftpsFolder, BatchTransferProgress batchTransferProgress)
          Similiar to sendFolder, except it creates the sendingFolder remotely and sends all its content recursively to the remote ftps folder ftpsFolder The progress can be monitored by registering BatchTransferProgress object with the method
 int sendFolderCreate(java.lang.String sendingFolder, java.lang.String ftpsFolder, BatchTransferProgress batchTransferProgress, boolean recursive)
          Similiar to sendFolderCreate, except recursive can be switched on/off
 void setImplicit(boolean isImplicit)
           
 void setKeyStoreFilePath(java.lang.String keyStoreFilePath)
           
 void setKeyStorePassword(java.lang.String keyStorePassword)
           
 void setPassive(boolean passive)
          Set passive to false if active mode is desired, passive is the default mode
 void setPassword(java.lang.String password)
           
 void setPort(int port)
          Use this when your FTP/SSL server is not 21
 void setServerName(java.lang.String serverName)
           
 void setUsername(java.lang.String username)
           
protected  boolean validate()
           
 
Methods inherited from class com.zehon.FileTransferClient
closeCache, getFileTransferPath, getLastModificationTime, getLastModificationTimeDate, sendFile, sendFile, sendFile, sendFile, sendFileOriginal, sendFiles, setLastModificationTime, setLastModificationTimeDate, writeToFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FTPsClient

public FTPsClient()
Empty constructor, used for Spring injection, otherwise use the other constructor.


FTPsClient

public FTPsClient(java.lang.String serverName,
                  java.lang.String username,
                  java.lang.String password,
                  boolean isImplicit)
Constructor with serverName, username and password as parameters, default standard port: 21.

Parameters:
serverName: - FTPS sername
username: - username for the FTPS server
password: - Password for the FTPS server
isImplicit - false for explicit (ftpes) this option is widely used, true for implicit (ftps).

FTPsClient

public FTPsClient(java.lang.String serverName,
                  int port,
                  java.lang.String username,
                  java.lang.String password,
                  boolean isImplicit)
Constructor with serverName, username and password as parameters.

Parameters:
serverName: - FTPS sername
port: - FTPS port
username: - username for the FTPS server
password: - Password for the FTPS server
isImplicit - false for explicit (ftpes) this option is widely used, true for implicit (ftps).

FTPsClient

public FTPsClient(java.lang.String serverName,
                  java.lang.String username,
                  java.lang.String password,
                  boolean isImplicit,
                  java.lang.String keyStoreFilePath,
                  java.lang.String keyStorePassword)
Constructor with serverName, username and password, isImplicit, keyStoreFilePath and keyStorePassword as parameters, default standard port: 21. keyStoreFilePath and keyStorePassword are needed when the FTP/SSL server forces data to be transferred in a secured way, in other word, internally Zehon sends your FTP/SSL server a PROT="P" command. Please refer to http://zehon.com/FTPs_tutorial.htm for more information on how to configure this.
Configure a keystore using jdk/keytool
Use this command to create your keystore
JDK_HOME/bin/keystore/keytool -genkeypair (i.e C:\Program Files\Java\jdk1.6.0_07\bin>keytool -genkeypair)
Answer all questions neccessary, make sure to remember your keystore password.
The .keystore file is usually stored in your home directory i.e C:\\Documents and Settings\\zehon\\.keystore or /home/zehon/.keystore

Parameters:
serverName: - FTPS servername
username: - username for the FTPS server
password: - password for the FTPS server
isImplicit - false for explicit (ftpes) this option is widely used, true for implicit (ftps).
keyStoreFilePath: - Path to your local keystore, i.e C:\\Documents and Settings\\zehon\\.keystore or /home/zehon/.keystore
keyStorePassword: - Password for the keystore

Troubleshooting tips:
explicit implicit
PROT P keystore keystore
PROT C no no
With no KeysTore configuration and the data transfer is required to be secured then the following is seen in the System.out
521 Data connection cannot be opened with this PROT setting: PROT P required


The following is seen when the client is implicit, but the server is explicit.
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?


The following is seen when the client is explicit, but the server is implicit.
The connection hangs.


FTPS debug can be set on command line for Java: "-Djavax.net.debug=ssl,handshake,sslctx,keymanager,trustmanager",


FTPsClient

public FTPsClient(java.lang.String serverName,
                  int port,
                  java.lang.String username,
                  java.lang.String password,
                  boolean isImplicit,
                  java.lang.String keyStoreFilePath,
                  java.lang.String keyStorePassword)
Constructor with serverName, username and password, isImplicit, keyStoreFilePath and keyStorePassword as parameters. keyStoreFilePath and keyStorePassword are needed when the FTP/SSL server forces data to be transferred in a secured way, in other word, internally Zehon sends your FTP/SSL server a PROT="P" command. Please refer to http://zehon.com/FTPs_tutorial.htm for more information on how to configure this.

Parameters:
serverName: - FTPS servername
port: - FTPS port
username: - username for the FTPS server
password: - password for the FTPS server
isImplicit - false for explicit (ftpes) this option is widely used, true for implicit (ftps).
keyStoreFilePath: - Path to your local keystore, i.e C:\\Documents and Settings\\zehon\\.keystore or /home/zehon/.keystore
keyStorePassword: - Password for the keystore
Method Detail

isPassive

public boolean isPassive()

setPassive

public void setPassive(boolean passive)
Set passive to false if active mode is desired, passive is the default mode

Parameters:
passive -

getPort

public int getPort()
Specified by:
getPort in class FileTransferClient

setPort

public void setPort(int port)
Use this when your FTP/SSL server is not 21

Specified by:
setPort in class FileTransferClient
Parameters:
port -

getKeyStoreFilePath

public java.lang.String getKeyStoreFilePath()

setKeyStoreFilePath

public void setKeyStoreFilePath(java.lang.String keyStoreFilePath)

getKeyStorePassword

public java.lang.String getKeyStorePassword()

setKeyStorePassword

public void setKeyStorePassword(java.lang.String keyStorePassword)

isImplicit

public boolean isImplicit()

setImplicit

public void setImplicit(boolean isImplicit)

getServerName

public java.lang.String getServerName()
Specified by:
getServerName in class FileTransferClient

setServerName

public void setServerName(java.lang.String serverName)
Specified by:
setServerName in class FileTransferClient

getUsername

public java.lang.String getUsername()
Specified by:
getUsername in class FileTransferClient

setUsername

public void setUsername(java.lang.String username)
Specified by:
setUsername in class FileTransferClient

getPassword

public java.lang.String getPassword()
Specified by:
getPassword in class FileTransferClient

setPassword

public void setPassword(java.lang.String password)
Specified by:
setPassword in class FileTransferClient

validate

protected boolean validate()
Overrides:
validate in class FileTransferClient

sendFile

public int sendFile(java.lang.String localFilePath,
                    java.lang.String ftpDestFolder)
             throws FileTransferException
Read in a file specified by localFilePath, for example: C:\myfiles\test.txt or /home/joe/images/img.jpg it does not matter if the file is of binary or text, and ftp it to a remote ftp folder specified by ftpDestFolder, i.e / or /ftpRoot or /myftpFolder.

Overrides:
sendFile in class FileTransferClient
Parameters:
localFilePath - Local file path including the file name for example: C:\myfiles\test.txt or /home/joe/images/img.jpg
ftpDestFolder - remote ftp folder, for example: / or /ftpRoot or /myftpFolder.
Returns:
FileTransferStatus.SUCCESS or FileTransferStatus.INVALID_SETTINGS (if username or password or servername is not found)
Throws:
FileTransferException - If there is an error loading or ftping the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.

for example:


try{
FTPsClient ftpClient = new FTPsClient("ftp.myhost.com", "ftp", "pass");
ftpClient.sendFile("C:\myfiles\test.txt", "/myftpFolder");
}catch(FileTransferException ex){
ex.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

sendFile

public int sendFile(java.lang.String localFilePath,
                    java.lang.String filetransferDestFolder,
                    java.lang.String nameOfFileToStore)
             throws FileTransferException
Similar to the other sendFile except you get to choose what name to be stored on the server

Overrides:
sendFile in class FileTransferClient
Parameters:
localFilePath -
filetransferDestFolder -
nameOfFileToStore -
Returns:
Throws:
FileTransferException
See Also:
FileTransferStatus

sendFile

public int sendFile(java.io.InputStream inputStream,
                    java.lang.String nameOfFileToStore,
                    java.lang.String ftpDestFolder)
             throws FileTransferException
Take any input stream (all classes that implement from java.io.InputStream) and read it to a buffer and FTPS it to a remote FTPS Server specified by ftpDestFolder i.e / or /ftpRoot or /myftpFolder, the name of the file stored is specified by nameOfFileToStore i.e "test.txt"

Overrides:
sendFile in class FileTransferClient
Parameters:
inputStream - an inputstream from a file (FileInputStream or a network input stream) anyclass that implements java.io.InputStream Note You must close the inputStream when you're done to avoid memory leak or running out of file descriptor. Look at the finally block in the example below for reference.
nameOfFileToStore - the name of the file to be stored i.e "test.txt"
ftpDestFolder - remote ftp folder, for example: / or /ftpRoot or /myftpFolder.
Returns:
FileTransferStatus.SUCCESS or FileTransferStatus.INVALID_SETTINGS (if username or password or servername is not found)
Throws:
FileTransferException - If there is an error ftping the stream, catch the exception and log it or print out the stack trace or its cause for debug purposes.

Example:


InputStream is = null;
String filePath = "C:\\myfiles\\project\\ftpProject\\files\\test.txt";
File localFile = new File(filePath);
try {
is = new BufferedInputStream(new FileInputStream(localFile));
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
String destFolder = "/myftpFolder";
String nameOfFile = "testStream.txt";
int status = -1;
try {
FTPsClient ftpClient = new FTPsClient("ftp.myhost.com", "ftp", "pass");
status = ftpClient.sendFile(is, nameOfFile, destFolder);
} catch (FileTransferException e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}finally{
if(is != null){try {is.close();} catch (IOException e) {}}
}

See Also:
FileTransferStatus

getFileAsStream

public java.io.InputStream getFileAsStream(java.lang.String remoteFileName,
                                           java.lang.String ftpFolder)
                                    throws FileTransferException
Retrieve a remote file specified by ftpFolder/remoteFileName as a stream

Overrides:
getFileAsStream in class FileTransferClient
Parameters:
remoteFileName - the name of the file on the remote server to retrieve, i.e test.txt
ftpFolder - remote ftp folder, for example: / or /ftpRoot or /myftpFolder.
Returns:
InputStream, (null if username or password or servername is not found) Note: You must close the inputStream when you're done to avoid memory leak or running out of file descriptor. Look at the finally block in the
Throws:
FileTransferException - If there is an error getting the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.

For example:


InputStream is = null;
String destFolder = "/test";
String nameOfFile = "testStream.txt";
try {
FTPsClient ftpClient = new FTPsClient("ftp.myhost.com", "ftp", "pass");
is = ftpClient.getFileAsStream(nameOfFile, destFolder);
} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}finally{
if(is != null){try {is.close();} catch (IOException e) {}}
}

See Also:
FileTransferStatus

getFile

public int getFile(java.lang.String remoteFileName,
                   java.lang.String ftpFolder,
                   java.lang.String toLocalFolder)
            throws FileTransferException
Retrieve a remote file specified by ftpFolder/remoteFileName and buffer it and write a local folder called toLocalFolder

Overrides:
getFile in class FileTransferClient
Parameters:
remoteFileName - the name of the file on the remote server to retrieve, i.e test.txt
ftpFolder - remote ftp folder, for example: / or /ftpRoot or /myftpFolder.
toLocalFolder - local filesystem folder to write the remote file to C:\\myfiles\\project\\ftpProject\\writeToFolder";
Returns:
FileTransferStatus.SUCCESS or FileTransferStatus.INVALID_SETTINGS (if username or password or servername is not found)
Throws:
FileTransferException - If there is an error getting the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.

For example:


String ftpFolder = "/test";
String nameOfFile = "testStream.txt";
String toLocalFolder = "C:\\myfiles\\project\\ftpProject\\writeToFolder";
int status = -1;
try {
FTPsClient ftpClient = new FTPsClient("ftp.myhost.com", "ftp", "pass");
status = ftpClient.getFile(nameOfFile, ftpFolder, toLocalFolder);

} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

deleteFile

public int deleteFile(java.lang.String nameOfFileToDelete,
                      java.lang.String ftpFolder)
               throws FileTransferException
Delete a remote file on the ftp server specified by ftpFolder/nameOfFileToDelete

Overrides:
deleteFile in class FileTransferClient
Parameters:
nameOfFileToDelete - the name of the file on the remote server to retrieve, i.e test.txt
ftpFolder - remote ftp folder, for example: / or /ftpRoot or /myftpFolder.
Returns:
FileTransferStatus.SUCCESS FileTransferStatus.FAILURE (if failed to delete the file) FileTransferStatus.FILE_NOT_EXISTS the file does not exist on the remote server or FileTransferStatus.INVALID_SETTINGS (if username or password or servername is not found)
Throws:
FileTransferException - If there is an error deleting the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.

For example:


String ftpFolder = "/test";
String nameOfFileToDelete = "test.txt";
int status = -1;
try {
FTPsClient ftpClient = new FTPsClient("ftp.myhost.com", "ftp", "pass");
status = ftpClient.deleteFile(nameOfFileToDelete, ftpFolder);

} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

createFolder

public int createFolder(java.lang.String nameOfFolderToCreate,
                        java.lang.String ftpsFolder)
                 throws FileTransferException
Create a remote file on the ftp server specified by ftpsFolder/nameOfFolderToCreate If the folder already exists returns successfully

Overrides:
createFolder in class FileTransferClient
Parameters:
nameOfFolderToCreate - the name of the folder to be created on the remote server
ftpsFolder - remote folder, for example: / or /filetransferRoot or /myftpsFolder.
Returns:
FileTransferStatus.SUCCESS or FileTransferStatus.INVALID_SETTINGS (if username or password or servername is not found)
Throws:
FileTransferException - If there is an error creating the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.

For example:


String ftpsFolder = "/test";
String nameOfFolderToCreate = "subFolderTest";
int status = -1;
try {
FTPsClient ftpClient = new FTPsClient("ftp.myhost.com", "ftp", "pass");
status = ftpClient.createFolder(nameOfFolderToCreate, ftpsFolder);

} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

moveFile

public int moveFile(java.lang.String nameOfFileToMove,
                    java.lang.String ftpFromFolder,
                    java.lang.String newNameOfFile,
                    java.lang.String ftpToFolder)
             throws FileTransferException
Move a remote file on the ftp server specified by ftpFromFolder/nameOfFileToMove to another remote folder with a new name specified ftpToFolder/newNameOfFile

Overrides:
moveFile in class FileTransferClient
Parameters:
nameOfFileToMove - the name of the file on the remote server to move, i.e test.txt
ftpFromFolder - remote ftp folder, for example: / or /ftpRoot or /myftpFolder.
newNameOfFile - the new name of the file on the remote server to after the move, i.e test.txt
ftpToFolder - remote ftp folder to move to, for example: / or /ftpRoot or /myftpFolder.
Returns:
FileTransferStatus.SUCCESS FileTransferStatus.FAILURE (if failed to delete the file) FileTransferStatus.FILE_NOT_EXISTS the file does not exist on the remote server or FileTransferStatus.INVALID_SETTINGS (if username or password or servername is not found)
Throws:
FileTransferException - If there is an error moving the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.

For example:


String ftpFromFolder = "/test";
String nameOfFileToMove = "test.txt";
String ftpToFolder = "/anotherfolder";
String newNameOfFile = "moved_test.txt";
int status = -1;
try {
FTPsClient ftpClient = new FTPsClient("ftp.myhost.com", "ftp", "pass");
status = ftpClient.moveFile(nameOfFileToMove, ftpFromFolder,newNameOfFile, ftpToFolder);
} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

copyFile

public int copyFile(java.lang.String sourceFilePath,
                    java.lang.String destFilePath)
             throws FileTransferException
Copy a remote file specified by sourceFilePath to another remote folder or file path specified by destFilePath. If sourceFilePath is a folder, all of its files will be copied to the new folder.

Overrides:
copyFile in class FileTransferClient
Parameters:
sourceFilePath - a file path with the file name or just a folder path
destFilePath - a file path with the file name or just a folder path
Returns:
FileTransferStatus.SUCCESS FileTransferStatus.FILE_NOT_EXISTS the file does not exist on the remote server or FileTransferStatus.INVALID_SETTINGS (if username or password or servername is not found)
Throws:
FileTransferException - If there is an error moving the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.

For example: Copying test.txt from the test folder to the upload folder with a new name call testCopy.txt


String sourceFilePath = "/test/test.txt";
String destFilePath = "/upload/testCopy.txt";
int status = -1;
try {
FTPsClient ftpClient = new FTPsClient("ftp.myhost.com", "ftp", "pass");
status = ftpClient.copy(sourceFilePath, destFilePath);
} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

Or:


//Copying all files in upload folder to folder uploadCopy
String sourceFilePath = "/upload";
String destFilePath = "/uploadCopy";
int status = -1;
try {
FTPsClient ftpClient = new FTPsClient("ftp.myhost.com", "ftp", "pass");
status = ftpClient.copy(sourceFilePath, destFilePath);
} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

getFolder

public int getFolder(java.lang.String ftpsFolder,
                     java.lang.String toLocalFolder,
                     BatchTransferProgress batchTransferProgress)
              throws FileTransferException
Retrieve a remote folder and all the containing filess specified by ftpsFolder recursively, write to a local folder called toLocalFolder ftpsFolder WILL NOT BE CREATED LOCALLY BUT ONLY ITS CONTENTS AND SUBDIRECTORIES REFER TO getFolderCreate if ftpsFolder needs to be created.

Parameters:
remoteFileName - the name of the file on the remote server to retrieve, i.e test.txt
ftpsFolder - remote ftps folder, for example: / or /ftpsRoot or /myftpsFolder.
toLocalFolder - local filesystem folder to write the folder to C:\\myfiles\\project\\ftpsProject\\writeToFolder";
Returns:
FileTransferStatus.SUCCESS or FileTransferStatus.INVALID_SETTINGS (if username or password or servername is not found)
Throws:
FileTransferException - If there is an error getting the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.

For example:


String ftpsFolder = "/test";
String toLocalFolder = "C:\\myfiles\\project\\ftpsProject\\writeToFolder";
int status = -1;
try {
FTPsClient ftpsClient = new FTPsClient("ftps.myhost.com", "ftps", "pass");
status = ftpsClient.getFolder(ftpsFolder, toLocalFolder, new BatchTransferProgressDefault());

} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

getFolder

public int getFolder(java.lang.String ftpsFolder,
                     java.lang.String toLocalFolder,
                     BatchTransferProgress batchTransferProgress,
                     boolean recursive)
              throws FileTransferException
Similiar to getFolder except recursive can be switched on/off

Parameters:
remoteFileName - the name of the file on the remote server to retrieve, i.e test.txt
ftpsFolder - remote ftps folder, for example: / or /ftpsRoot or /myftpsFolder.
toLocalFolder - local filesystem folder to write the folder to C:\\myfiles\\project\\ftpsProject\\writeToFolder";
Returns:
FileTransferStatus.SUCCESS or FileTransferStatus.INVALID_SETTINGS (if username or password or servername is not found)
Throws:
FileTransferException - If there is an error getting the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.

For example:


String ftpsFolder = "/test";
String toLocalFolder = "C:\\myfiles\\project\\ftpsProject\\writeToFolder";
int status = -1;
try {
FTPsClient ftpsClient = new FTPsClient("ftps.myhost.com", "ftps", "pass");
status = ftpsClient.getFolder(ftpsFolder, toLocalFolder, new BatchTransferProgressDefault(), false);

} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

getFolderCreate

public int getFolderCreate(java.lang.String ftpsFolder,
                           java.lang.String toLocalFolder,
                           BatchTransferProgress batchTransferProgress)
                    throws FileTransferException
Similiar to getFolder except it creates ftpsFolder locally in toLocalFolder and retrieve all the containing filess specified by ftpsFolder recursively, write to a local folder called toLocalFolder

Parameters:
remoteFileName - the name of the file on the remote server to retrieve, i.e test.txt
ftpsFolder - remote ftps folder, for example: / or /ftpsRoot or /myftpsFolder.
toLocalFolder - local filesystem folder to write the folder to C:\\myfiles\\project\\ftpsProject\\writeToFolder";
Returns:
FileTransferStatus.SUCCESS or FileTransferStatus.INVALID_SETTINGS (if username or password or servername is not found)
Throws:
FileTransferException - If there is an error getting the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.

For example:


String ftpsFolder = "/test";
String toLocalFolder = "C:\\myfiles\\project\\ftpsProject\\writeToFolder";
int status = -1;
try {
FTPsClient ftpsClient = new FTPsClient("ftps.myhost.com", "ftps", "pass", new BatchTransferProgressDefault());
status = ftpsClient.getFolderCreate(ftpsFolder, toLocalFolder);

} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

getFolderCreate

public int getFolderCreate(java.lang.String ftpsFolder,
                           java.lang.String toLocalFolder,
                           BatchTransferProgress batchTransferProgress,
                           boolean recursive)
                    throws FileTransferException
Similiar to getFolderCreate except recursive can be switched on/off

Parameters:
remoteFileName - the name of the file on the remote server to retrieve, i.e test.txt
ftpsFolder - remote ftps folder, for example: / or /ftpsRoot or /myftpsFolder.
toLocalFolder - local filesystem folder to write the folder to C:\\myfiles\\project\\ftpsProject\\writeToFolder";
Returns:
FileTransferStatus.SUCCESS or FileTransferStatus.INVALID_SETTINGS (if username or password or servername is not found)
Throws:
FileTransferException - If there is an error getting the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.

For example:


String ftpsFolder = "/test";
String toLocalFolder = "C:\\myfiles\\project\\ftpsProject\\writeToFolder";
int status = -1;
try {
FTPsClient ftpsClient = new FTPsClient("ftps.myhost.com", "ftps", "pass");
status = ftpsClient.getFolderCreate(ftpsFolder, toLocalFolder, new BatchTransferProgressDefault(), false);

} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

getFolder

protected int getFolder(java.lang.String filetransferFolder,
                        java.lang.String toLocalFolder,
                        BatchTransferProgress batchTransferProgress,
                        boolean justFolderContent,
                        boolean recursive)
                 throws FileTransferException
Overrides:
getFolder in class FileTransferClient
Throws:
FileTransferException

getFileNamesInFolder

public java.lang.String[] getFileNamesInFolder(java.lang.String ftpFolder)
                                        throws FileTransferException
Retrieve all filenames in a remote folder specified by ftpFolder

Overrides:
getFileNamesInFolder in class FileTransferClient
Parameters:
ftpFolder - remote ftp folder, for example: / or /ftpRoot or /myftpFolder.
Returns:
Array of file names
Throws:
FileTransferException - If there is an error getting the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.

For example:


String ftpFolder = "/test";
int status = -1;
try {
FTPsClient ftpClient = new FTPsClient("ftp.myhost.com", "ftp", "pass");
String[] names = ftpClient.getFileNamesInFolder(ftpFolder);

} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

sendFolder

public int sendFolder(java.lang.String sendingFolder,
                      java.lang.String ftpsFolder,
                      BatchTransferProgress batchTransferProgress)
               throws FileTransferException
Transfer all files and subdirectories recursively from sendingFolder, for example: C:\myfiles or /home/joe/images to the remote ftps folder ftpsFolder. The progress can be monitored by registering BatchTransferProgress object with the method, set null to it if monitoring is not needed. The sendingFolder WILL NOT BE CREATED REMOTELY BUT ONLY ITS CONTENTS AND SUBDIRECTORIES REFER TO sendFolderCreate if sendingFolder need to be created.

Parameters:
sendingFolder - Local folder to be uploaded: C:\myfiles or /home/joe/images
ftpsDestFolder - remote ftps folder to upload to, for example: / or /ftpsRoot or /myftpsFolder.
batchTransferProgress - an object that gets notified when a file starts or ends transfering. You can set it to null if you choose to not monitor the progress.
Returns:
FileTransferStatus.SUCCESS or FileTransferStatus.INVALID_SETTINGS (if username or password or servername is not found)
Throws:
FileTransferException - If there is an error loading or ftpsing the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.

for example:


try{
FTPsClient ftpsClient = new FTPsClient("ftps.myhost.com", "ftps", "pass");
ftpsClient.sendFolder("C:\myfiles", "/myftpsFolder", new BatchTransferProgressDefault());
}catch(FileTransferException ex){
ex.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

sendFolder

public int sendFolder(java.lang.String sendingFolder,
                      java.lang.String ftpsFolder,
                      BatchTransferProgress batchTransferProgress,
                      boolean recursive)
               throws FileTransferException
Similiar to sendFolder, only recursive can be switched on and off The progress can be monitored by registering BatchTransferProgress object with the method

Parameters:
sendingFolder - Local folder to be uploaded: C:\myfiles or /home/joe/images
ftpsDestFolder - remote ftps folder to upload to, for example: / or /ftpsRoot or /myftpsFolder.
batchTransferProgress - an object that gets notified when a file starts or ends transfering. You can set it to null if you choose to not monitor the progress.
Returns:
FileTransferStatus.SUCCESS or FileTransferStatus.INVALID_SETTINGS (if username or password or servername is not found)
Throws:
FileTransferException - If there is an error loading or ftpsing the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.

for example:


try{
FTPsClient ftpsClient = new FTPsClient("ftps.myhost.com", "ftps", "pass");
ftpsClient.sendFolder("C:\myfiles", "/myftpsFolder", new BatchTransferProgressDefault(), false);
}catch(FileTransferException ex){
ex.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

sendFolderCreate

public int sendFolderCreate(java.lang.String sendingFolder,
                            java.lang.String ftpsFolder,
                            BatchTransferProgress batchTransferProgress)
                     throws FileTransferException
Similiar to sendFolder, except it creates the sendingFolder remotely and sends all its content recursively to the remote ftps folder ftpsFolder The progress can be monitored by registering BatchTransferProgress object with the method

Parameters:
sendingFolder - Local folder to be uploaded: C:\myfiles or /home/joe/images
ftpsDestFolder - remote ftps folder to upload to, for example: / or /ftpsRoot or /myftpsFolder.
batchTransferProgress - an object that gets notified when a file starts or ends transfering. You can set it to null if you choose to not monitor the progress.
Returns:
FileTransferStatus.SUCCESS or FileTransferStatus.INVALID_SETTINGS (if username or password or servername is not found)
Throws:
FileTransferException - If there is an error loading or ftpsing the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.

for example:


try{
FTPsClient ftpsClient = new FTPsClient("ftps.myhost.com", "ftps", "pass");
ftpsClient.sendFolderCreate("C:\myfiles", "/myftpsFolder", new BatchTransferProgressDefault());
}catch(FileTransferException ex){
ex.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

sendFolderCreate

public int sendFolderCreate(java.lang.String sendingFolder,
                            java.lang.String ftpsFolder,
                            BatchTransferProgress batchTransferProgress,
                            boolean recursive)
                     throws FileTransferException
Similiar to sendFolderCreate, except recursive can be switched on/off

Parameters:
sendingFolder - Local folder to be uploaded: C:\myfiles or /home/joe/images
ftpsDestFolder - remote ftps folder to upload to, for example: / or /ftpsRoot or /myftpsFolder.
batchTransferProgress - an object that gets notified when a file starts or ends transfering. You can set it to null if you choose to not monitor the progress.
Returns:
FileTransferStatus.SUCCESS or FileTransferStatus.INVALID_SETTINGS (if username or password or servername is not found)
Throws:
FileTransferException - If there is an error loading or ftpsing the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.

for example:


try{
FTPsClient ftpsClient = new FTPsClient("ftps.myhost.com", "ftps", "pass");
ftpsClient.sendFolderCreate("C:\myfiles", "/myftpsFolder", new BatchTransferProgressDefault(), false);
}catch(FileTransferException ex){
ex.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

sendFolder

protected int sendFolder(java.lang.String sendingFolder,
                         java.lang.String filetransferFolder,
                         BatchTransferProgress batchTransferProgress,
                         boolean justFolderContent,
                         boolean recursive)
                  throws FileTransferException
Overrides:
sendFolder in class FileTransferClient
Throws:
FileTransferException

folderExists

public boolean folderExists(java.lang.String ftpFolder)
                     throws FileTransferException
Check if the remote ftpFolder exists

Overrides:
folderExists in class FileTransferClient
Parameters:
ftpFolder -
Returns:
true if exists false otherwise
Throws:
FileTransferException -

For example:
String ftpFolder = "/test";
try {
FTPsClient ftpClient = new FTPsClient("ftp.myhost.com", "ftp", "pass");
boolean exists = ftpClient.folderExists(ftpFolder);

} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}


fileExists

public boolean fileExists(java.lang.String ftpFolder,
                          java.lang.String nameOfFile)
                   throws FileTransferException
Check if the remote ftp file exists

Overrides:
fileExists in class FileTransferClient
Parameters:
ftpFolder -
nameOfFile -
Returns:
true if exists false otherwise
Throws:
FileTransferException -

For example:
String ftpFolder = "/test";
String nameOfFile = "existFile.txt";
try {
FTPsClient ftpClient = new FTPsClient("ftp.myhost.com", "ftp", "pass");
boolean exists = ftpClient.fileExists(ftpFolder, nameOfFile);

} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}


getFileSystemOptions

protected org.apache.commons.vfs.FileSystemOptions getFileSystemOptions()
                                                                 throws org.apache.commons.vfs.FileSystemException
Specified by:
getFileSystemOptions in class FileTransferClient
Throws:
org.apache.commons.vfs.FileSystemException

getProtocol

protected java.lang.String getProtocol()
Specified by:
getProtocol in class FileTransferClient


Copyright © 2009 Zehon Team. All Rights Reserved.