com.zehon
Class FileTransferClient

java.lang.Object
  extended by com.zehon.FileTransferClient
Direct Known Subclasses:
FTPClient, FTPsClient, SFTPClient

public abstract class FileTransferClient
extends java.lang.Object

This FileTransferClient abstract 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.htm for more information about our FileTransfer package

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

Constructor Summary
FileTransferClient()
           
 
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.
protected  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.
protected  int createFolder(java.lang.String nameOfFolderToCreate, java.lang.String filetransferFolder)
          Create a remote file on the filetransfer server specified by filetransferFolder/nameOfFolderToCreate If the folder already exists returns successfully
protected  int deleteFile(java.lang.String nameOfFileToDelete, java.lang.String filetransferFolder)
          Delete a remote file on the filetransfer server specified by filetransferFolder/nameOfFileToDelete
protected  boolean fileExists(java.lang.String folderPath, java.lang.String fileName)
          Check if the remote file exists
protected  boolean folderExists(java.lang.String folderPath)
          Check if the remote folder exists
protected  int getFile(java.lang.String remoteFileName, java.lang.String filetransferFolder, java.lang.String toLocalFolder)
          Retrieve a remote file specified by filetransferFolder/remoteFileName and buffer it and write a local folder called toLocalFolder
protected  java.io.InputStream getFileAsStream(java.lang.String remoteFileName, java.lang.String filetransferFolder)
          Retrieve a remote file specified by filetransferFolder/remoteFileName as a stream
protected  java.lang.String[] getFileNamesInFolder(java.lang.String filetransferFolder)
           
protected abstract  org.apache.commons.vfs.FileSystemOptions getFileSystemOptions()
           
protected  java.lang.String getFileTransferPath(java.lang.String hostname, java.lang.String username, java.lang.String password, int port)
           
protected  int getFolder(java.lang.String filetransferFolder, java.lang.String toLocalFolder, BatchTransferProgress batchTransferProgress, boolean justFolderContent, boolean recursive)
           
protected  long getLastModificationTime(java.lang.String filePath)
          Get last modification time of a file or a folder
protected  java.util.Date getLastModificationTimeDate(java.lang.String filePath)
          Get last modification time of a file or a folder
abstract  java.lang.String getPassword()
           
abstract  int getPort()
           
protected abstract  java.lang.String getProtocol()
           
abstract  java.lang.String getServerName()
           
abstract  java.lang.String getUsername()
           
protected  int moveFile(java.lang.String nameOfFileToMove, java.lang.String filetransferFromFolder, java.lang.String newNameOfFile, java.lang.String filetransferToFolder)
          Move a remote file on the filetransfer server specified by filetransferFromFolder/nameOfFileToMove to another remote folder with a new name specified filetransferToFolder/newNameOfFile
 int sendFile(byte[] fileContent, java.lang.String ftpDestFolder, java.lang.String nameOfFileToStore)
          Upload fileContent to ftpDestFolder and name it nameOfFileToStore
 int sendFile(java.io.File file, java.lang.String ftpDestFolder)
          Upload a java.io.File to ftpDestFolder
 int sendFile(java.io.File file, java.lang.String ftpDestFolder, java.lang.String nameOfFileToStore)
           
protected  int sendFile(java.io.InputStream inputStream, java.lang.String nameOfFileToStore, java.lang.String filetransferDestFolder)
          Take any input stream (all classes that implement from java.io.InputStream) and read it to a buffer and FileTransfer it to a remote FileTransfer Server specified by filetransferDestFolder i.e / or /filetransferRoot or /myfiletransferFolder, the name of the file stored is specified by nameOfFileToStore i.e "test.txt"
protected  int sendFile(java.lang.String localFilePath, java.lang.String filetransferDestFolder)
          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 filetransfer it to a remote filetransfer folder specified by filetransferDestFolder, i.e / or /filetransferRoot or /myfiletransferFolder.
 int sendFile(java.lang.String localFilePath, java.lang.String ftpDestFolder, java.lang.String nameOfFileToStore)
          Upload a file from localFilePath to ftpDestFolder and name it nameOfFileToStore
protected  int sendFile(java.lang.String localFilePath, java.lang.String filetransferDestFolder, java.lang.String nameOfFileToStore, boolean retainLastUpdate)
          Similar to the other sendFile except you get to choose what name to be stored on the server and whether to retain the last update of the file to the file on the ftp server.
protected  int sendFileOriginal(java.lang.String localFilePath, java.lang.String filetransferDestFolder)
           
 int sendFiles(java.lang.String fromFolder, java.lang.String filePatternRegex, java.lang.String ftpDestFolder)
          Find all files that match filePatternRegex in fromFolder and send them to ftpDestFolder
protected  int sendFolder(java.lang.String sendingFolder, java.lang.String filetransferFolder, BatchTransferProgress batchTransferProgress, boolean justFolderContent, boolean recursive)
           
protected  void setLastModificationTime(java.lang.String filePath, long modificationTime)
          Set last modification time of a file or a folder
protected  void setLastModificationTimeDate(java.lang.String filePath, java.util.Date modificationDate)
          Set last modification time of a file or a folder
abstract  void setPassword(java.lang.String password)
           
abstract  void setPort(int port)
           
abstract  void setServerName(java.lang.String serverName)
           
abstract  void setUsername(java.lang.String username)
           
protected  boolean validate()
           
protected  void writeToFile(java.io.InputStream inputStream, java.lang.String toLocalFolder, java.lang.String remoteFileName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileTransferClient

public FileTransferClient()
Method Detail

getServerName

public abstract java.lang.String getServerName()

setServerName

public abstract void setServerName(java.lang.String serverName)

getUsername

public abstract java.lang.String getUsername()

setUsername

public abstract void setUsername(java.lang.String username)

getPassword

public abstract java.lang.String getPassword()

setPassword

public abstract void setPassword(java.lang.String password)

getPort

public abstract int getPort()

setPort

public abstract void setPort(int port)

getProtocol

protected abstract java.lang.String getProtocol()

getFileSystemOptions

protected abstract org.apache.commons.vfs.FileSystemOptions getFileSystemOptions()
                                                                          throws org.apache.commons.vfs.FileSystemException
Throws:
org.apache.commons.vfs.FileSystemException

validate

protected boolean validate()

sendFile

protected int sendFile(java.lang.String localFilePath,
                       java.lang.String filetransferDestFolder)
                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 filetransfer it to a remote filetransfer folder specified by filetransferDestFolder, i.e / or /filetransferRoot or /myfiletransferFolder.

Parameters:
localFilePath - Local file path including the file name for example: C:\myfiles\test.txt or /home/joe/images/img.jpg
filetransferDestFolder - remote filetransfer folder, for example: / or /filetransferRoot or /myfiletransferFolder.
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 filetransfering the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.

for example:


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

See Also:
FileTransferStatus

sendFileOriginal

protected int sendFileOriginal(java.lang.String localFilePath,
                               java.lang.String filetransferDestFolder)
                        throws FileTransferException
Throws:
FileTransferException

sendFile

public int sendFile(java.lang.String localFilePath,
                    java.lang.String ftpDestFolder,
                    java.lang.String nameOfFileToStore)
             throws FileTransferException
Upload a file from localFilePath to ftpDestFolder and name it nameOfFileToStore

Parameters:
localFilePath -
ftpDestFolder -
nameOfFileToStore -
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 filetransfering the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.
See Also:
FileTransferStatus

sendFile

public int sendFile(byte[] fileContent,
                    java.lang.String ftpDestFolder,
                    java.lang.String nameOfFileToStore)
             throws FileTransferException
Upload fileContent to ftpDestFolder and name it nameOfFileToStore

Parameters:
fileContent - byte array content to be storeed
ftpDestFolder -
nameOfFileToStore -
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 filetransfering the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.
See Also:
FileTransferStatus

sendFile

public int sendFile(java.io.File file,
                    java.lang.String ftpDestFolder)
             throws FileTransferException
Upload a java.io.File to ftpDestFolder

Parameters:
file - java.io.File
ftpDestFolder -
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 filetransfering the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.
See Also:
FileTransferStatus

sendFile

public int sendFile(java.io.File file,
                    java.lang.String ftpDestFolder,
                    java.lang.String nameOfFileToStore)
             throws FileTransferException
Parameters:
file -
ftpDestFolder -
nameOfFileToStore -
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 filetransfering the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.
See Also:
FileTransferStatus

sendFiles

public int sendFiles(java.lang.String fromFolder,
                     java.lang.String filePatternRegex,
                     java.lang.String ftpDestFolder)
              throws FileTransferException
Find all files that match filePatternRegex in fromFolder and send them to ftpDestFolder

Parameters:
fromFolder - local folder i.e C:\\myfiles
filePatternRegex - i.e "(.)+" = all files "(.)+\\.txt"=all files with extension .txt
ftpDestFolder - i.e \zehon\ftpFolder
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 filetransfering the file, catch the exception and log it or print out the stack trace or its cause for debug purposes.

for example:

See Also:
FileTransferStatus

sendFile

protected int sendFile(java.lang.String localFilePath,
                       java.lang.String filetransferDestFolder,
                       java.lang.String nameOfFileToStore,
                       boolean retainLastUpdate)
                throws FileTransferException
Similar to the other sendFile except you get to choose what name to be stored on the server and whether to retain the last update of the file to the file on the ftp server.

Parameters:
localFilePath -
filetransferDestFolder -
nameOfFileToStore -
retainLastUpdate - if true the lastModified property of the file(localFilePath) with be on the tranferred file
Returns:
Throws:
FileTransferException

sendFile

protected int sendFile(java.io.InputStream inputStream,
                       java.lang.String nameOfFileToStore,
                       java.lang.String filetransferDestFolder)
                throws FileTransferException
Take any input stream (all classes that implement from java.io.InputStream) and read it to a buffer and FileTransfer it to a remote FileTransfer Server specified by filetransferDestFolder i.e / or /filetransferRoot or /myfiletransferFolder, 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"
filetransferDestFolder - remote filetransfer folder, for example: / or /filetransferRoot or /myfiletransferFolder.
Returns:
FileTransferStatus.SUCCESS or FileTransferStatus.INVALID_SETTINGS (if username or password or servername is not found)
Throws:
FileTransferException - If there is an error filetransfering 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\\filetransferProject\\files\\test.txt";
File localFile = new File(filePath);
try {
is = new BufferedInputStream(new FileInputStream(localFile));
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
String destFolder = "/myfiletransferFolder";
String nameOfFile = "testStream.txt";
int status = -1;
try {
FileTransferClient filetransferClient = new FileTransferClient("filetransfer.myhost.com", "filetransfer", "pass");
status = filetransferClient.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

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

Parameters:
remoteFileName - the name of the file on the remote server to retrieve, i.e test.txt
filetransferFolder - remote filetransfer folder, for example: / or /filetransferRoot or /myfiletransferFolder.
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 {
FileTransferClient filetransferClient = new FileTransferClient("filetransfer.myhost.com", "filetransfer", "pass");
is = filetransferClient.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

protected int getFile(java.lang.String remoteFileName,
                      java.lang.String filetransferFolder,
                      java.lang.String toLocalFolder)
               throws FileTransferException
Retrieve a remote file specified by filetransferFolder/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
filetransferFolder - remote filetransfer folder, for example: / or /filetransferRoot or /myfiletransferFolder.
toLocalFolder - local filesystem folder to write the remote file to C:\\myfiles\\project\\filetransferProject\\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 filetransferFolder = "/test";
String nameOfFile = "testStream.txt";
String toLocalFolder = "C:\\myfiles\\project\\filetransferProject\\writeToFolder";
int status = -1;
try {
FileTransferClient filetransferClient = new FileTransferClient("filetransfer.myhost.com", "filetransfer", "pass");
status = filetransferClient.getFile(nameOfFile, filetransferFolder, toLocalFolder);

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

See Also:
FileTransferStatus

writeToFile

protected void writeToFile(java.io.InputStream inputStream,
                           java.lang.String toLocalFolder,
                           java.lang.String remoteFileName)
                    throws java.lang.Exception
Throws:
java.lang.Exception

deleteFile

protected int deleteFile(java.lang.String nameOfFileToDelete,
                         java.lang.String filetransferFolder)
                  throws FileTransferException
Delete a remote file on the filetransfer server specified by filetransferFolder/nameOfFileToDelete

Parameters:
nameOfFileToDelete - the name of the file on the remote server to retrieve, i.e test.txt
filetransferFolder - remote filetransfer folder, for example: / or /filetransferRoot or /myfiletransferFolder.
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 filetransferFolder = "/test";
String nameOfFileToDelete = "test.txt";
int status = -1;
try {
FileTransferClient filetransferClient = new FileTransferClient("filetransfer.myhost.com", "filetransfer", "pass");
status = filetransferClient.deleteFile(nameOfFileToDelete, filetransferFolder);

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

See Also:
FileTransferStatus

createFolder

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

Parameters:
nameOfFolderToCreate - the name of the folder to be created on the remote server
filetransferFolder - remote folder, for example: / or /filetransferRoot or /myfiletransferFolder.
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 filetransferFolder = "/test";
String nameOfFolderToCreate = "subFolderTest";
int status = -1;
try {
FileTransferClient filetransferClient = new FileTransferClient("filetransfer.myhost.com", "filetransfer", "pass");
status = filetransferClient.createFolder(nameOfFolderToCreate, filetransferFolder);

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

See Also:
FileTransferStatus

folderExists

protected boolean folderExists(java.lang.String folderPath)
                        throws FileTransferException
Check if the remote folder exists

Parameters:
folderPath -
Returns:
true if exists false otherwise
Throws:
FileTransferException

fileExists

protected boolean fileExists(java.lang.String folderPath,
                             java.lang.String fileName)
                      throws FileTransferException
Check if the remote file exists

Parameters:
folderPath - remote folder
fileName - remote file
Returns:
true if exists false otherwise
Throws:
FileTransferException

moveFile

protected int moveFile(java.lang.String nameOfFileToMove,
                       java.lang.String filetransferFromFolder,
                       java.lang.String newNameOfFile,
                       java.lang.String filetransferToFolder)
                throws FileTransferException
Move a remote file on the filetransfer server specified by filetransferFromFolder/nameOfFileToMove to another remote folder with a new name specified filetransferToFolder/newNameOfFile

Parameters:
nameOfFileToMove - the name of the file on the remote server to move, i.e test.txt
filetransferFromFolder - remote filetransfer folder, for example: / or /filetransferRoot or /myfiletransferFolder.
newNameOfFile - the new name of the file on the remote server to after the move, i.e test.txt
filetransferToFolder - remote filetransfer folder to move to, for example: / or /filetransferRoot or /myfiletransferFolder.
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 filetransferFromFolder = "/test";
String nameOfFileToMove = "test.txt";
String filetransferToFolder = "/anotherfolder";
String newNameOfFile = "moved_test.txt";
int status = -1;
try {
FileTransferClient filetransferClient = new FileTransferClient("filetransfer.myhost.com", "filetransfer", "pass");
status = filetransferClient.moveFile(nameOfFileToMove, filetransferFromFolder,newNameOfFile, filetransferToFolder);
} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

copyFile

protected 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.

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 {
FileTransferClient filetransferClient = new FileTransferClient("filetransfer.myhost.com", "filetransfer", "pass");
status = filetransferClient.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 {
FileTransferClient filetransferClient = new FileTransferClient("filetransfer.myhost.com", "filetransfer", "pass");
status = filetransferClient.copy(sourceFilePath, destFilePath);
} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}

See Also:
FileTransferStatus

getFileTransferPath

protected java.lang.String getFileTransferPath(java.lang.String hostname,
                                               java.lang.String username,
                                               java.lang.String password,
                                               int port)

getFolder

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

getFileNamesInFolder

protected java.lang.String[] getFileNamesInFolder(java.lang.String filetransferFolder)
                                           throws FileTransferException
Throws:
FileTransferException

sendFolder

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

getLastModificationTime

protected long getLastModificationTime(java.lang.String filePath)
                                throws FileTransferException
Get last modification time of a file or a folder

Parameters:
filePath - a file path with the file name or just a folder path
Returns:
milliseconds representing the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.
Throws:
FileTransferException - If invalid settings or the file or folder does not exist or If there is an error getting last modification time

getLastModificationTimeDate

protected java.util.Date getLastModificationTimeDate(java.lang.String filePath)
                                              throws FileTransferException
Get last modification time of a file or a folder

Parameters:
filePath - a file path with the file name or just a folder path
Returns:
java.util.Date of the last modification date of the remote file
Throws:
FileTransferException - If invalid settings or the file or folder does not exist or If there is an error getting last modification time

setLastModificationTime

protected void setLastModificationTime(java.lang.String filePath,
                                       long modificationTime)
                                throws FileTransferException
Set last modification time of a file or a folder

Parameters:
filePath - a file path with the file name or just a folder path
modificationTime - long value of milliseconds representing the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.
Throws:
FileTransferException - If invalid settings or the file or folder does not exist or If there is an error setting last modification time

setLastModificationTimeDate

protected void setLastModificationTimeDate(java.lang.String filePath,
                                           java.util.Date modificationDate)
                                    throws FileTransferException
Set last modification time of a file or a folder

Parameters:
filePath - a file path with the file name or just a folder path
modificationDate - java.util.Date value
Throws:
FileTransferException - If invalid settings or the file or folder does not exist or If there is an error setting last modification time

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 SFTP-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:
protected static void main(String[] args) {
String username = "sftp";
String host = "localhost";
String password = "sftp";
SFTPClient sftpClient = new SFTPClient();
sftpClient.setServerName(host);
sftpClient.setUsername(username);
sftpClient.setPassword(password);

String sftpFolder = "/test";
String nameOfFile = "testStream.txt";
String toLocalFolder = "C:\\myfiles\\writeToFolder";
int status = -1;
try {
status = sftpClient.getFile(nameOfFile, sftpFolder, toLocalFolder);

} catch (Exception e) {
e.printStackTrace();
}
try {
sftpClient.closeCache();
} catch (FileTransferException e) {
e.printStackTrace();
}
}

Throws:
FileTransferException


Copyright © 2009 Zehon Team. All Rights Reserved.