Package co.ecg.alpaca.core.framework
Class FTPClient
java.lang.Object
co.ecg.alpaca.core.framework.FTPClient
Class that provides methods to connect to a FTP server
and perform various tasks.
- Version:
- $Id: $Id
- Author:
- DavidKelley on 6/29/16.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCloses a FTPClient with a connection.voidCreates a FTPClient with a connection given using credentials from the FTPServer object.booleandeleteFile(String path) Method to delete file from FTP server.downloadFile(String fileName) Downloads a file using the FTPClient.Getter for the fieldaddress.Getter for the fieldpassword.intgetPort()Getter for the fieldport.Getter for the fieldusername.booleanMethod to check if there is an active conenction to the FTP ServervoidsetAddress(String address) Setter for the fieldaddress.voidsetPassword(String password) Setter for the fieldpassword.voidsetPort(int port) Setter for the fieldport.voidsetUsername(String username) Setter for the fieldusername.booleanuploadFile(File file) uploadFile.booleanuploadFile(String localFilePath, String remoteFileName) Uploads a file to the FTp Server.
-
Constructor Details
-
FTPClient
Constructor for FTPClient.
- Parameters:
address- aStringobject.
-
-
Method Details
-
getAddress
Getter for the field
address.- Returns:
- a
Stringobject.
-
setAddress
Setter for the field
address.- Parameters:
address- aStringobject.
-
getPort
public int getPort()Getter for the field
port.- Returns:
- a int.
-
setPort
public void setPort(int port) Setter for the field
port.- Parameters:
port- a int.
-
getUsername
Getter for the field
username.- Returns:
- a
Stringobject.
-
setUsername
Setter for the field
username.- Parameters:
username- aStringobject.
-
getPassword
Getter for the field
password.- Returns:
- a
Stringobject.
-
setPassword
Setter for the field
password.- Parameters:
password- aStringobject.
-
connectFTPClient
Creates a FTPClient with a connection given using credentials from the FTPServer object.- Throws:
FTPException- Thrown if the server address is null or login is unsuccessful.IOException- Throw if there is an error during connection.
-
closeFTPConnection
Closes a FTPClient with a connection.- Throws:
IOException- Throw if an error occurs during disconnection.
-
downloadFile
Downloads a file using the FTPClient.- Parameters:
fileName- The name of the file to be downloaded.- Returns:
- Returns an
InputStreamcontaining the downloaded file. - Throws:
IOException- Thrown if an FTP error occurs.FTPException- Thrown if the download fails or the FTPServer is not connected.
-
uploadFile
public boolean uploadFile(String localFilePath, String remoteFileName) throws IOException, FTPException Uploads a file to the FTp Server.- Parameters:
localFilePath- The path of the file to be uploaded.remoteFileName- The name of the file to be stored.- Returns:
- Returns n
Booleantrue if file was uploaded, false if a failure occurred. - Throws:
IOException- Thrown if an FTP error occurs.FTPException- Thrown if the FTP server is not connected.
-
uploadFile
uploadFile.
- Parameters:
file- aFileobject.- Returns:
- a boolean.
- Throws:
IOException- if any.FTPException- if any.
-
deleteFile
Method to delete file from FTP server.- Parameters:
path- The path of the file to delete.- Returns:
- Returns
Booleantrue if file was deleted, false if a failure occurred. - Throws:
IOException- Thrown if an FTP error occurs.FTPException- Thrown if the FTP server is not connected.
-
isConnected
public boolean isConnected()Method to check if there is an active conenction to the FTP Server- Returns:
- Returns a
Booleantrue if connected, false otherwise.
-