com.zehon.ftp
Class FTP

java.lang.Object
  extended by com.zehon.ftp.FTP

public class FTP
extends java.lang.Object

This FTP class offers convenient static methods for uploading/downloading files and doing remote file options such as move, copy, etc.. Please refer to http://www.zehon.com/features_ftp.htm for more information about our FTP.

Author:
Zehon Team http://www.zehon.com/

Method Summary
static void closeCache()
          Clean up the global cache Clean up all cache threads before your stand-alone application exits, helping it terminate the parent thread instead of hanging because the cache's thread
is still running.
static int copyFile(java.lang.String sourceFilePath, java.lang.String destFilePath, java.lang.String serverName, java.lang.String username, java.lang.String password)
          Copy a remote file specified by sourceFilePath to another remote folder or file path specified by destFilePath.
static int createFolder(java.lang.String nameOfFolderToCreate, java.lang.String ftpFolder, java.lang.String serverName, java.lang.String username, java.lang.String password)
          Create a remote file on the ftp server specified by ftpFolder/nameOfFolderToCreate If the folder already exists returns successfully
static int deleteFile(java.lang.String nameOfFileToDelete, java.lang.String ftpFolder, java.lang.String serverName, java.lang.String username, java.lang.String password)
          Delete a remote file on the ftp server specified by ftpFolder/nameOfFileToDelete
static boolean fileExists(java.lang.String ftpFolder, java.lang.String nameOfFile, java.lang.String serverName, java.lang.String username, java.lang.String password)
          Check if the remote ftp file exists
static boolean folderExists(java.lang.String ftpFolder, java.lang.String serverName, java.lang.String username, java.lang.String password)
          Check if the remote ftpFolder exists
static int getFile(java.lang.String remoteFileName, java.lang.String ftpFolder, java.lang.String serverName, java.lang.String username, java.lang.String password, java.lang.String toLocalFolder)
          Retrieve a remote file specified by ftpFolder/remoteFileName and buffer it and write a local folder called toLocalFolder
static java.io.InputStream getFileAsStream(java.lang.String remoteFileName, java.lang.String ftpFolder, java.lang.String serverName, java.lang.String username, java.lang.String password)
          Retrieve a remote file specified by ftpFolder/remoteFileName as a stream
static java.lang.String[] getFileNamesInFolder(java.lang.String ftpFolder, java.lang.String serverName, java.lang.String username, java.lang.String password)
          Retrieve all filenames in a remote folder specified by ftpFolder
static int getFolder(java.lang.String ftpFolder, java.lang.String toLocalFolder, BatchTransferProgress batchTransferProgress, java.lang.String serverName, java.lang.String username, java.lang.String password)
          Retrieve a remote folder specified by ftpFolder write to a local folder called toLocalFolder
static int getFolderCreate(java.lang.String ftpFolder, java.lang.String toLocalFolder, BatchTransferProgress batchTransferProgress, java.lang.String serverName, java.lang.String username, java.lang.String password)
          Similiar to getFolder except it creates ftpFolder locally in toLocalFolder and retrieve all the containing filess specified by ftpFolder recursively, write to a local folder called toLocalFolder
static int moveFile(java.lang.String nameOfFileToMove, java.lang.String ftpFromFolder, java.lang.String newNameOfFile, java.lang.String ftpToFolder, java.lang.String serverName, java.lang.String username, java.lang.String password)
          Move a remote file on the ftp server specified by ftpFromFolder/nameOfFileToMove to another remote folder with a new name specified ftpToFolder/newNameOfFile
static int sendFile(java.io.InputStream inputStream, java.lang.String nameOfFileToStore, java.lang.String ftpDestFolder, java.lang.String serverName, java.lang.String username, java.lang.String password)
          Take any input stream (all classes that implement from java.io.InputStream) and read it to a buffer and FTP it to a remote FTP Server specified by ftpDestFolder i.e / or /ftpRoot or /myftpFolder, the name of the file stored is specified by nameOfFileToStore i.e "test.txt"
static int sendFile(java.lang.String localFilePath, java.lang.String ftpDestFolder, java.lang.String serverName, java.lang.String username, java.lang.String password)
          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.
static int sendFile(java.lang.String localFilePath, java.lang.String ftpDestFolder, java.lang.String nameOfFileToStore, java.lang.String serverName, java.lang.String username, java.lang.String password)
          Similar to the other sendFile except you get to choose what name to be stored on the server
static int sendFolder(java.lang.String sendingFolder, java.lang.String ftpFolder, BatchTransferProgress batchTransferProgress, java.lang.String serverName, java.lang.String username, java.lang.String password)
          Transfer all files or subdirectories recursively from sendingFolder, for example: C:\myfiles or /home/joe/images to the remote ftp folder ftpFolder The progress can be monitored by registering BatchTransferProgress object with the method
static int sendFolderCreate(java.lang.String sendingFolder, java.lang.String ftpFolder, BatchTransferProgress batchTransferProgress, java.lang.String serverName, java.lang.String username, java.lang.String password)
          Similiar to sendFolder, except it creates the sendingFolder remotely and sends all its content recursively to the remote ftp folder ftpFolder The progress can be monitored by registering BatchTransferProgress object with the method
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

sendFile

public static int sendFile(java.lang.String localFilePath,
                           java.lang.String ftpDestFolder,
                           java.lang.String serverName,
                           java.lang.String username,
                           java.lang.String password)
                    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.

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.
serverName - ftp server name
username - ftp username
password - ftp password
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{
 FTP.sendFile("C:\myfiles\test.txt", "/myftpFolder", "ftp.myhost.com", "ftp", "pass" );
}catch(FileTransferException ex){
 ex.printStackTrace();
 //or
 //ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

sendFile

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

Parameters:
localFilePath -
ftpDestFolder -
nameOfFileToStore -
serverName -
username -
password -
Returns:
Throws:
FileTransferException

sendFile

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

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.
serverName - ftp server name
username - ftp username
password - ftp password
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 {
 status = FTP.sendFile(is, nameOfFile, destFolder, "ftp.myhost.com", "ftp", "pass" );
} 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 static java.io.InputStream getFileAsStream(java.lang.String remoteFileName,
                                                  java.lang.String ftpFolder,
                                                  java.lang.String serverName,
                                                  java.lang.String username,
                                                  java.lang.String password)
                                           throws FileTransferException
Retrieve a remote file specified by ftpFolder/remoteFileName as a stream

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.
serverName - ftp server name
username - ftp username
password - ftp password
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{
is = FTP.getFileAsStream(nameOfFile, destFolder, "ftp.myhost.com", "ftp", "pass" );
} 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 static int getFile(java.lang.String remoteFileName,
                          java.lang.String ftpFolder,
                          java.lang.String serverName,
                          java.lang.String username,
                          java.lang.String password,
                          java.lang.String toLocalFolder)
                   throws FileTransferException
Retrieve a remote file specified by ftpFolder/remoteFileName and buffer it and write a local folder called toLocalFolder

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";
serverName - ftp server name
username - ftp username
password - ftp password
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 {
status = FTP.getFile(nameOfFile, ftpFolder, toLocalFolder,"ftp.myhost.com", "ftp", "pass");
} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

deleteFile

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

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
serverName - ftp server name
username - ftp username
password - ftp password
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 {
status = FTP.deleteFile(nameOfFileToDelete, ftpFolder,"ftp.myhost.com", "ftp", "pass");
} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

createFolder

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

Parameters:
nameOfFolderToCreate - the name of the folder to be created on the remote server
ftpFolder - remote folder, for example: / or /filetransferRoot 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 creating 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 nameOfFolderToCreate = "subFolderTest";
int status = -1;
try {
status = FTP.createFolder(nameOfFolderToCreate, ftpFolder,"ftp.myhost.com", "ftp", "pass");

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

See Also:
FileTransferStatus

moveFile

public static int moveFile(java.lang.String nameOfFileToMove,
                           java.lang.String ftpFromFolder,
                           java.lang.String newNameOfFile,
                           java.lang.String ftpToFolder,
                           java.lang.String serverName,
                           java.lang.String username,
                           java.lang.String password)
                    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

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.
serverName - ftp server name
username - ftp username
password - ftp password
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 {
FTP.moveFile(nameOfFileToMove, ftpFromFolder,newNameOfFile, ftpToFolder, "ftp.myhost.com", "ftp", "pass");
} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

copyFile

public static int copyFile(java.lang.String sourceFilePath,
                           java.lang.String destFilePath,
                           java.lang.String serverName,
                           java.lang.String username,
                           java.lang.String password)
                    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.

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
serverName - ftp server name
username - ftp username
password - ftp password
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 {
status = FTP.copy(sourceFilePath, destFilePath, "ftp.myhost.com", "ftp", "pass");
} 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 {=
status = FTP.copy(sourceFilePath, destFilePath, "ftp.myhost.com", "ftp", "pass");
} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

getFolder

public static int getFolder(java.lang.String ftpFolder,
                            java.lang.String toLocalFolder,
                            BatchTransferProgress batchTransferProgress,
                            java.lang.String serverName,
                            java.lang.String username,
                            java.lang.String password)
                     throws FileTransferException
Retrieve a remote folder specified by ftpFolder write to a local folder called toLocalFolder

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 folder to C:\\myfiles\\project\\ftpProject\\writeToFolder";
serverName - ftp server name
username - ftp username
password - ftp password
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 toLocalFolder = "C:\\myfiles\\project\\ftpProject\\writeToFolder";
int status = -1;
try {
status = FTP.getFolder(ftpFolder, toLocalFolder, new BatchTransferProgressDefault(), "ftp.myhost.com", "ftps", "pass" );

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

See Also:
FileTransferStatus

getFolderCreate

public static int getFolderCreate(java.lang.String ftpFolder,
                                  java.lang.String toLocalFolder,
                                  BatchTransferProgress batchTransferProgress,
                                  java.lang.String serverName,
                                  java.lang.String username,
                                  java.lang.String password)
                           throws FileTransferException
Similiar to getFolder except it creates ftpFolder locally in toLocalFolder and retrieve all the containing filess specified by ftpFolder 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
ftpFolder - remote ftp folder, for example: / or /ftpRoot or /myftpFolder.
toLocalFolder - local filesystem folder to write the folder to C:\\myfiles\\project\\ftpProject\\writeToFolder";
serverName - ftp server name
username - ftp username
password - ftp password
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 toLocalFolder = "C:\\myfiles\\project\\ftpProject\\writeToFolder";
int status = -1;
try {
status = FTP.getFolderCreate(ftpFolder, toLocalFolder, new BatchTransferProgressDefault(), "ftp.myhost.com", "ftps", "pass" );

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

See Also:
FileTransferStatus

getFileNamesInFolder

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

Parameters:
ftpFolder - remote ftp folder, for example: / or /ftpRoot or /myftpFolder.
serverName - ftp server name
username - ftp username
password - ftp password
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 {
String[] names = FTP.getFileNamesInFolder(ftpFolder, "ftp.myhost.com", "ftp", "pass");

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

See Also:
FileTransferStatus

sendFolder

public static int sendFolder(java.lang.String sendingFolder,
                             java.lang.String ftpFolder,
                             BatchTransferProgress batchTransferProgress,
                             java.lang.String serverName,
                             java.lang.String username,
                             java.lang.String password)
                      throws FileTransferException
Transfer all files or subdirectories recursively from sendingFolder, for example: C:\myfiles or /home/joe/images to the remote ftp folder ftpFolder 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
ftpDestFolder - remote ftp folder to upload to, for example: / or /ftpRoot or /myftpFolder.
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.
serverName - ftp server name
username - ftp username
password - ftp password
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{
int status = FTP.sendFolder("C:\myfiles", "/myftpFolder", new BatchTransferProgressDefault(), "ftp.myhost.com", "ftp", "pass");
}catch(FileTransferException ex){
ex.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

sendFolderCreate

public static int sendFolderCreate(java.lang.String sendingFolder,
                                   java.lang.String ftpFolder,
                                   BatchTransferProgress batchTransferProgress,
                                   java.lang.String serverName,
                                   java.lang.String username,
                                   java.lang.String password)
                            throws FileTransferException
Similiar to sendFolder, except it creates the sendingFolder remotely and sends all its content recursively to the remote ftp folder ftpFolder 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
ftpDestFolder - remote ftp folder to upload to, for example: / or /ftpRoot or /myftpFolder.
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.
serverName - ftp server name
username - ftp username
password - ftp password
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{
int status = FTP.sendFolderCreate("C:\myfiles", "/myftpFolder", new BatchTransferProgressDefault(), "ftp.myhost.com", "ftp", "pass");
}catch(FileTransferException ex){
ex.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

folderExists

public static boolean folderExists(java.lang.String ftpFolder,
                                   java.lang.String serverName,
                                   java.lang.String username,
                                   java.lang.String password)
                            throws FileTransferException
Check if the remote ftpFolder exists

Parameters:
ftpFolder -
serverName - ftp server name
username - ftp username
password - ftp password
Returns:
true if exists false otherwise
Throws:
FileTransferException -

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

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


fileExists

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

Parameters:
ftpFolder -
nameOfFile -
serverName - ftp server name
username - ftp username
password - ftp password
Returns:
true if exists false otherwise
Throws:
FileTransferException -

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

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


closeCache

public static void closeCache()
                       throws FileTransferException
Clean up the global cache Clean up all cache threads before your stand-alone application exits, helping it terminate the parent thread instead of hanging because the cache's thread
is still running. YOU DON'T HAVE TO DO THIS, it is completely OK to have the global cache thread running still,
but if it bothers you about having running threads and you don't need to do FTP-ing any more then do this.
ONLY DO THIS BEFORE THE JVM EXITS (before the main() method exits)
DON'T USE IT IF THE APPLICATION IS RUNNING WITHIN A SERVLET CONTAINER, UNLESS YOU
CAN HOOK IT TO THE SHUTDOWN MECHANISM OF THE CONTAINER. Example:
public static void main(String[] args) {
String ftpFolder = "/test";
String nameOfFile = "testStream.txt";
String toLocalFolder = "C:\\myfiles\\writeToFolder";
int status = -1;
try {
status = FTP.getFile(nameOfFile, ftpFolder, toLocalFolder,"ftp.myhost.com", "ftp", "pass");

} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}
try {
FTP.closeCache();
} catch (FileTransferException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

Throws:
FileTransferException


Copyright 2009 Zehon Team. All Rights Reserved.