|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.zehon.FileTransferClient
com.zehon.ftp.FTPClient
public class FTPClient
This FTPClient
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_ftp.htm for more information about our FTP.
Constructor Summary | |
---|---|
FTPClient()
Empty constructor, used for Spring injection, otherwise use the other constructor. |
|
FTPClient(java.lang.String serverName,
int port,
java.lang.String username,
java.lang.String password)
Constructor with serverName, port, username and password as parameters. |
|
FTPClient(java.lang.String serverName,
java.lang.String username,
java.lang.String password)
Constructor with serverName, username and password as parameters default FTP 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 ftpFolder)
Create a remote file on the ftp server specified by ftpFolder/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 ftpFolder,
java.lang.String toLocalFolder,
BatchTransferProgress batchTransferProgress)
Retrieve a remote folder and all the containing filess specified by ftpFolder recursively, write to a local folder called toLocalFolder ftpFolder WILL NOT BE CREATED LOCALLY BUT ONLY ITS CONTENTS AND SUBDIRECTORIES REFER TO getFolderCreate if ftpFolder needs to be created. |
int |
getFolder(java.lang.String ftpFolder,
java.lang.String toLocalFolder,
BatchTransferProgress batchTransferProgress,
boolean recursive)
Similiar to getFolder except recursive can be switched on/off |
int |
getFolderCreate(java.lang.String ftpFolder,
java.lang.String toLocalFolder,
BatchTransferProgress batchTransferProgress)
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 |
int |
getFolderCreate(java.lang.String ftpFolder,
java.lang.String toLocalFolder,
BatchTransferProgress batchTransferProgress,
boolean recursive)
Similiar to getFolderCreate except recursive can be switched on/off |
long |
getLastModificationTime(java.lang.String filePath)
Get last modification or update time of a file or a folder |
java.util.Date |
getLastModificationTimeDate(java.lang.String filePath)
Get last modification or update time of a file or a folder as a java.util.Date object |
java.lang.String |
getPassword()
|
int |
getPort()
|
protected java.lang.String |
getProtocol()
|
java.lang.String |
getServerName()
|
java.lang.String |
getUsername()
|
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 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" |
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 ftpFolder,
BatchTransferProgress batchTransferProgress)
Transfer all files and subdirectories recursively from sendingFolder, for example: C:\myfiles or /home/joe/images to the remote ftp folder ftpFolder. |
int |
sendFolder(java.lang.String sendingFolder,
java.lang.String ftpFolder,
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 |
int |
sendFolderCreate(java.lang.String sendingFolder,
java.lang.String ftpFolder,
BatchTransferProgress batchTransferProgress)
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 |
int |
sendFolderCreate(java.lang.String sendingFolder,
java.lang.String ftpFolder,
BatchTransferProgress batchTransferProgress,
boolean recursive)
Similiar to sendFolderCreate, except recursive can be switched on/off |
void |
setPassword(java.lang.String password)
|
void |
setPort(int port)
|
void |
setServerName(java.lang.String serverName)
|
void |
setUsername(java.lang.String username)
|
protected boolean |
validate()
|
Methods inherited from class com.zehon.FileTransferClient |
---|
closeCache, getFileTransferPath, getFolder, sendFile, sendFile, sendFile, sendFile, sendFileOriginal, sendFiles, sendFolder, setLastModificationTime, setLastModificationTimeDate, writeToFile |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FTPClient()
public FTPClient(java.lang.String serverName, java.lang.String username, java.lang.String password)
serverName:
- FTP sernameusername:
- username for the FTP serverpassword:
- Password for the FTP serverpublic FTPClient(java.lang.String serverName, int port, java.lang.String username, java.lang.String password)
serverName:
- FTP sernameport:
- FTP portusername:
- username for the FTP serverpassword:
- Password for the FTP serverMethod Detail |
---|
public java.lang.String getServerName()
getServerName
in class FileTransferClient
public void setServerName(java.lang.String serverName)
setServerName
in class FileTransferClient
public java.lang.String getUsername()
getUsername
in class FileTransferClient
public void setUsername(java.lang.String username)
setUsername
in class FileTransferClient
public java.lang.String getPassword()
getPassword
in class FileTransferClient
public void setPassword(java.lang.String password)
setPassword
in class FileTransferClient
public int getPort()
getPort
in class FileTransferClient
public void setPort(int port)
setPort
in class FileTransferClient
protected boolean validate()
validate
in class FileTransferClient
public int sendFile(java.lang.String localFilePath, java.lang.String ftpDestFolder) throws FileTransferException
sendFile
in class FileTransferClient
localFilePath
- Local file path including the file name for example: C:\myfiles\test.txt or /home/joe/images/img.jpgftpDestFolder
- remote ftp folder, for example: / or /ftpRoot or /myftpFolder.
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{
FTPClient ftpClient = new FTPClient("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)
}
FileTransferStatus
public int sendFile(java.lang.String localFilePath, java.lang.String filetransferDestFolder, java.lang.String nameOfFileToStore) throws FileTransferException
sendFile
in class FileTransferClient
localFilePath
- filetransferDestFolder
- nameOfFileToStore
-
FileTransferException
FileTransferStatus
public int sendFile(java.io.InputStream inputStream, java.lang.String nameOfFileToStore, java.lang.String ftpDestFolder) throws FileTransferException
sendFile
in class FileTransferClient
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.
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) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String destFolder = "/myftpFolder";
String nameOfFile = "testStream.txt";
int status = -1;
try {
FTPClient ftpClient = new FTPClient("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) {}}
}
FileTransferStatus
public java.io.InputStream getFileAsStream(java.lang.String remoteFileName, java.lang.String ftpFolder) throws FileTransferException
getFileAsStream
in class FileTransferClient
remoteFileName
- the name of the file on the remote server to retrieve, i.e test.txtftpFolder
- remote ftp folder, for example: / or /ftpRoot or /myftpFolder.
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 {
FTPClient ftpClient = new FTPClient("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) {}}
}
FileTransferStatus
public int getFile(java.lang.String remoteFileName, java.lang.String ftpFolder, java.lang.String toLocalFolder) throws FileTransferException
getFile
in class FileTransferClient
remoteFileName
- the name of the file on the remote server to retrieve, i.e test.txtftpFolder
- remote ftp folder, for example: / or /ftpRoot or /myftpFolder.toLocalFolder
- local filesystem folder to write the remote file to C:\\myfiles\\project\\ftpProject\\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 ftpFolder = "/test";
String nameOfFile = "testStream.txt";
String toLocalFolder = "C:\\myfiles\\project\\ftpProject\\writeToFolder";
int status = -1;
try {
FTPClient ftpClient = new FTPClient("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)
}
FileTransferStatus
public int deleteFile(java.lang.String nameOfFileToDelete, java.lang.String ftpFolder) throws FileTransferException
deleteFile
in class FileTransferClient
nameOfFileToDelete
- the name of the file on the remote server to retrieve, i.e test.txtftpFolder
- remote ftp folder, for example: / or /ftpRoot or /myftpFolder.
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 {
FTPClient ftpClient = new FTPClient("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)
}
FileTransferStatus
public int createFolder(java.lang.String nameOfFolderToCreate, java.lang.String ftpFolder) throws FileTransferException
createFolder
in class FileTransferClient
nameOfFolderToCreate
- the name of the folder to be created on the remote serverftpFolder
- remote folder, for example: / or /filetransferRoot or /myftpFolder.
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 {
FTPClient ftpClient = new FTPClient("ftp.myhost.com", "ftp", "pass");
status = ftpClient.createFolder(nameOfFolderToCreate, ftpFolder);
} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}
FileTransferStatus
public int moveFile(java.lang.String nameOfFileToMove, java.lang.String ftpFromFolder, java.lang.String newNameOfFile, java.lang.String ftpToFolder) throws FileTransferException
moveFile
in class FileTransferClient
nameOfFileToMove
- the name of the file on the remote server to move, i.e test.txtftpFromFolder
- 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.txtftpToFolder
- remote ftp folder to move to, for example: / or /ftpRoot or /myftpFolder.
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 {
FTPClient ftpClient = new FTPClient("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)
}
FileTransferStatus
public int copyFile(java.lang.String sourceFilePath, java.lang.String destFilePath) throws FileTransferException
copyFile
in class FileTransferClient
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
String sourceFilePath = "/test/test.txt";
String destFilePath = "/upload/testCopy.txt";
int status = -1;
try {
FTPClient ftpClient = new FTPClient("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 {
FTPClient ftpClient = new FTPClient("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)
}
FileTransferStatus
public int getFolder(java.lang.String ftpFolder, java.lang.String toLocalFolder, BatchTransferProgress batchTransferProgress) throws FileTransferException
remoteFileName
- the name of the file on the remote server to retrieve, i.e test.txtftpFolder
- remote ftp folder, for example: / or /ftpRoot or /myftpFolder.toLocalFolder
- local filesystem folder to write the folder to C:\\myfiles\\project\\ftpProject\\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 ftpFolder = "/test";
String toLocalFolder = "C:\\myfiles\\project\\ftpProject\\writeToFolder";
int status = -1;
try {
FTPClient ftpClient = new FTPClient("ftp.myhost.com", "ftp", "pass");
status = ftpClient.getFolder(ftpFolder, toLocalFolder, new BatchTransferProgressDefault());
} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}
FileTransferStatus
public int getFolder(java.lang.String ftpFolder, java.lang.String toLocalFolder, BatchTransferProgress batchTransferProgress, boolean recursive) throws FileTransferException
remoteFileName
- the name of the file on the remote server to retrieve, i.e test.txtftpFolder
- remote ftp folder, for example: / or /ftpRoot or /myftpFolder.toLocalFolder
- local filesystem folder to write the folder to C:\\myfiles\\project\\ftpProject\\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 ftpFolder = "/test";
String toLocalFolder = "C:\\myfiles\\project\\ftpProject\\writeToFolder";
int status = -1;
try {
FTPClient ftpClient = new FTPClient("ftp.myhost.com", "ftp", "pass");
status = ftpClient.getFolder(ftpFolder, toLocalFolder, new BatchTransferProgressDefault(), false);
} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}
FileTransferStatus
public int getFolderCreate(java.lang.String ftpFolder, java.lang.String toLocalFolder, BatchTransferProgress batchTransferProgress) throws FileTransferException
remoteFileName
- the name of the file on the remote server to retrieve, i.e test.txtftpFolder
- remote ftp folder, for example: / or /ftpRoot or /myftpFolder.toLocalFolder
- local filesystem folder to write the folder to C:\\myfiles\\project\\ftpProject\\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 ftpFolder = "/test";
String toLocalFolder = "C:\\myfiles\\project\\ftpProject\\writeToFolder";
int status = -1;
try {
FTPClient ftpClient = new FTPClient("ftp.myhost.com", "ftp", "pass");
status = ftpClient.getFolderCreate(ftpFolder, toLocalFolder);
} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}
FileTransferStatus
public int getFolderCreate(java.lang.String ftpFolder, java.lang.String toLocalFolder, BatchTransferProgress batchTransferProgress, boolean recursive) throws FileTransferException
remoteFileName
- the name of the file on the remote server to retrieve, i.e test.txtftpFolder
- remote ftp folder, for example: / or /ftpRoot or /myftpFolder.toLocalFolder
- local filesystem folder to write the folder to C:\\myfiles\\project\\ftpProject\\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 ftpFolder = "/test";
String toLocalFolder = "C:\\myfiles\\project\\ftpProject\\writeToFolder";
int status = -1;
try {
FTPClient ftpClient = new FTPClient("ftp.myhost.com", "ftp", "pass");
status = ftpClient.getFolderCreate(ftpFolder, toLocalFolder);
} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}
FileTransferStatus
public java.lang.String[] getFileNamesInFolder(java.lang.String ftpFolder) throws FileTransferException
getFileNamesInFolder
in class FileTransferClient
ftpFolder
- remote ftp folder, for example: / or /ftpRoot or /myftpFolder.
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 {
FTPClient ftpClient = new FTPClient("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)
}
FileTransferStatus
public int sendFolder(java.lang.String sendingFolder, java.lang.String ftpFolder, BatchTransferProgress batchTransferProgress) throws FileTransferException
sendingFolder
- Local folder to be uploaded: C:\myfiles or /home/joe/imagesftpDestFolder
- 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.
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{
FTPClient ftpClient = new FTPClient("ftp.myhost.com", "ftp", "pass");
ftpClient.sendFolder("C:\myfiles", "/myftpFolder", new BatchTransferProgressDefault());
}catch(FileTransferException ex){
ex.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}
FileTransferStatus
public int sendFolder(java.lang.String sendingFolder, java.lang.String ftpFolder, BatchTransferProgress batchTransferProgress, boolean recursive) throws FileTransferException
sendingFolder
- Local folder to be uploaded: C:\myfiles or /home/joe/imagesftpDestFolder
- 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.
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{
FTPClient ftpClient = new FTPClient("ftp.myhost.com", "ftp", "pass");
ftpClient.sendFolder("C:\myfiles", "/myftpFolder", new BatchTransferProgressDefault(), false);
}catch(FileTransferException ex){
ex.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}
FileTransferStatus
public int sendFolderCreate(java.lang.String sendingFolder, java.lang.String ftpFolder, BatchTransferProgress batchTransferProgress) throws FileTransferException
sendingFolder
- Local folder to be uploaded: C:\myfiles or /home/joe/imagesftpDestFolder
- 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.
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{
FTPClient ftpClient = new FTPClient("ftp.myhost.com", "ftp", "pass");
ftpClient.sendFolderCreate("C:\myfiles", "/myftpFolder", new BatchTransferProgressDefault());
}catch(FileTransferException ex){
ex.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}
FileTransferStatus
public int sendFolderCreate(java.lang.String sendingFolder, java.lang.String ftpFolder, BatchTransferProgress batchTransferProgress, boolean recursive) throws FileTransferException
sendingFolder
- Local folder to be uploaded: C:\myfiles or /home/joe/imagesftpDestFolder
- 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.
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{
FTPClient ftpClient = new FTPClient("ftp.myhost.com", "ftp", "pass");
ftpClient.sendFolderCreate("C:\myfiles", "/myftpFolder", new BatchTransferProgressDefault(), false);
}catch(FileTransferException ex){
ex.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}
FileTransferStatus
public boolean folderExists(java.lang.String ftpFolder) throws FileTransferException
folderExists
in class FileTransferClient
ftpFolder
-
FileTransferException
- For example:
String ftpFolder = "/test";
try {
FTPClient ftpClient = new FTPClient("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)
}
public boolean fileExists(java.lang.String ftpFolder, java.lang.String nameOfFile) throws FileTransferException
fileExists
in class FileTransferClient
ftpFolder
- nameOfFile
-
FileTransferException
- For example:
String ftpFolder = "/test";
String nameOfFile = "existFile.txt";
try {
FTPClient ftpClient = new FTPClient("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)
}
public long getLastModificationTime(java.lang.String filePath) throws FileTransferException
getLastModificationTime
in class FileTransferClient
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 time
For example:
String filePath = "/test/test.txt";
try {
FTPClient ftpClient = new FTPClient("ftp.myhost.com", "ftp", "pass");
long modTime = ftpClient.getLastModificationTime(filePath);
} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}
public java.util.Date getLastModificationTimeDate(java.lang.String filePath) throws FileTransferException
getLastModificationTimeDate
in class FileTransferClient
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 time
For example:
String filePath = "/test/test.txt";
try {
FTPClient ftpClient = new FTPClient("ftp.myhost.com", "ftp", "pass");
Date modDate = ftpClient.getLastModificationTime(filePath);
} catch (Exception e) {
e.printStackTrace();
//or
//ex.getCause().printStackTrace(); (Depending on what version of JDK you use)
}
protected org.apache.commons.vfs.FileSystemOptions getFileSystemOptions() throws org.apache.commons.vfs.FileSystemException
getFileSystemOptions
in class FileTransferClient
org.apache.commons.vfs.FileSystemException
protected java.lang.String getProtocol()
getProtocol
in class FileTransferClient
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |