|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.zehon.FileTransferClient
public abstract class FileTransferClient
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
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 |
---|
public FileTransferClient()
Method Detail |
---|
public abstract java.lang.String getServerName()
public abstract void setServerName(java.lang.String serverName)
public abstract java.lang.String getUsername()
public abstract void setUsername(java.lang.String username)
public abstract java.lang.String getPassword()
public abstract void setPassword(java.lang.String password)
public abstract int getPort()
public abstract void setPort(int port)
protected abstract java.lang.String getProtocol()
protected abstract org.apache.commons.vfs.FileSystemOptions getFileSystemOptions() throws org.apache.commons.vfs.FileSystemException
org.apache.commons.vfs.FileSystemException
protected boolean validate()
protected int sendFile(java.lang.String localFilePath, java.lang.String filetransferDestFolder) throws FileTransferException
localFilePath
- Local file path including the file name for example: C:\myfiles\test.txt or /home/joe/images/img.jpgfiletransferDestFolder
- remote filetransfer folder, for example: / or /filetransferRoot or /myfiletransferFolder.
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)
}
FileTransferStatus
protected int sendFileOriginal(java.lang.String localFilePath, java.lang.String filetransferDestFolder) throws FileTransferException
FileTransferException
public int sendFile(java.lang.String localFilePath, java.lang.String ftpDestFolder, java.lang.String nameOfFileToStore) throws FileTransferException
localFilePath
- ftpDestFolder
- nameOfFileToStore
-
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.FileTransferStatus
public int sendFile(byte[] fileContent, java.lang.String ftpDestFolder, java.lang.String nameOfFileToStore) throws FileTransferException
fileContent
- byte array content to be storeedftpDestFolder
- nameOfFileToStore
-
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.FileTransferStatus
public int sendFile(java.io.File file, java.lang.String ftpDestFolder) throws FileTransferException
file
- java.io.FileftpDestFolder
-
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.FileTransferStatus
public int sendFile(java.io.File file, java.lang.String ftpDestFolder, java.lang.String nameOfFileToStore) throws FileTransferException
file
- ftpDestFolder
- nameOfFileToStore
-
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.FileTransferStatus
public int sendFiles(java.lang.String fromFolder, java.lang.String filePatternRegex, java.lang.String ftpDestFolder) throws FileTransferException
fromFolder
- local folder i.e C:\\myfilesfilePatternRegex
- i.e "(.)+" = all files "(.)+\\.txt"=all files with extension .txtftpDestFolder
- i.e \zehon\ftpFolder
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:
FileTransferStatus
protected int sendFile(java.lang.String localFilePath, java.lang.String filetransferDestFolder, java.lang.String nameOfFileToStore, boolean retainLastUpdate) throws FileTransferException
localFilePath
- filetransferDestFolder
- nameOfFileToStore
- retainLastUpdate
- if true the lastModified property of the file(localFilePath) with be on the tranferred file
FileTransferException
protected int sendFile(java.io.InputStream inputStream, java.lang.String nameOfFileToStore, java.lang.String filetransferDestFolder) throws FileTransferException
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.
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) {}}
}
FileTransferStatus
protected java.io.InputStream getFileAsStream(java.lang.String remoteFileName, java.lang.String filetransferFolder) throws FileTransferException
remoteFileName
- the name of the file on the remote server to retrieve, i.e test.txtfiletransferFolder
- remote filetransfer folder, for example: / or /filetransferRoot or /myfiletransferFolder.
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) {}}
}
FileTransferStatus
protected int getFile(java.lang.String remoteFileName, java.lang.String filetransferFolder, java.lang.String toLocalFolder) throws FileTransferException
remoteFileName
- the name of the file on the remote server to retrieve, i.e test.txtfiletransferFolder
- remote filetransfer folder, for example: / or /filetransferRoot or /myfiletransferFolder.toLocalFolder
- local filesystem folder to write the remote file to C:\\myfiles\\project\\filetransferProject\\writeToFolder";
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)
}
FileTransferStatus
protected void writeToFile(java.io.InputStream inputStream, java.lang.String toLocalFolder, java.lang.String remoteFileName) throws java.lang.Exception
java.lang.Exception
protected int deleteFile(java.lang.String nameOfFileToDelete, java.lang.String filetransferFolder) throws FileTransferException
nameOfFileToDelete
- the name of the file on the remote server to retrieve, i.e test.txtfiletransferFolder
- remote filetransfer folder, for example: / or /filetransferRoot or /myfiletransferFolder.
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)
}
FileTransferStatus
protected int createFolder(java.lang.String nameOfFolderToCreate, java.lang.String filetransferFolder) throws FileTransferException
nameOfFolderToCreate
- the name of the folder to be created on the remote serverfiletransferFolder
- remote folder, for example: / or /filetransferRoot or /myfiletransferFolder.
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)
}
FileTransferStatus
protected boolean folderExists(java.lang.String folderPath) throws FileTransferException
folderPath
-
FileTransferException
protected boolean fileExists(java.lang.String folderPath, java.lang.String fileName) throws FileTransferException
folderPath
- remote folderfileName
- remote file
FileTransferException
protected int moveFile(java.lang.String nameOfFileToMove, java.lang.String filetransferFromFolder, java.lang.String newNameOfFile, java.lang.String filetransferToFolder) throws FileTransferException
nameOfFileToMove
- the name of the file on the remote server to move, i.e test.txtfiletransferFromFolder
- 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.txtfiletransferToFolder
- remote filetransfer folder to move to, for example: / or /filetransferRoot or /myfiletransferFolder.
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)
}
FileTransferStatus
protected int copyFile(java.lang.String sourceFilePath, java.lang.String destFilePath) throws FileTransferException
sourceFilePath
- a file path with the file name or just a folder pathdestFilePath
- a file path with the file name or just a folder path
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
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)
}
FileTransferStatus
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) throws FileTransferException
FileTransferException
protected java.lang.String[] getFileNamesInFolder(java.lang.String filetransferFolder) throws FileTransferException
FileTransferException
protected int sendFolder(java.lang.String sendingFolder, java.lang.String filetransferFolder, BatchTransferProgress batchTransferProgress, boolean justFolderContent, boolean recursive) throws FileTransferException
FileTransferException
protected long getLastModificationTime(java.lang.String filePath) throws FileTransferException
filePath
- a file path with the file name or just a folder path
FileTransferException
- If invalid settings or the file or folder does not exist or
If there is an error getting last modification timeprotected java.util.Date getLastModificationTimeDate(java.lang.String filePath) throws FileTransferException
filePath
- a file path with the file name or just a folder path
FileTransferException
- If invalid settings or the file or folder does not exist or
If there is an error getting last modification timeprotected void setLastModificationTime(java.lang.String filePath, long modificationTime) throws FileTransferException
filePath
- a file path with the file name or just a folder pathmodificationTime
- 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.
FileTransferException
- If invalid settings or the file or folder does not exist or
If there is an error setting last modification timeprotected void setLastModificationTimeDate(java.lang.String filePath, java.util.Date modificationDate) throws FileTransferException
filePath
- a file path with the file name or just a folder pathmodificationDate
- java.util.Date value
FileTransferException
- If invalid settings or the file or folder does not exist or
If there is an error setting last modification timepublic static void closeCache() throws FileTransferException
FileTransferException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |