Package co.ecg.alpaca.core.framework
Class FTPClient
- java.lang.Object
-
- co.ecg.alpaca.core.framework.FTPClient
-
public class FTPClient extends Object
Class that provides methods to connect to a FTP server and perform various tasks.- Version:
- $Id: $Id
- Author:
- DavidKelley on 6/29/16.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcloseFTPConnection()Closes a FTPClient with a connection.voidconnectFTPClient()Creates a FTPClient with a connection given using credentials from the FTPServer object.booleandeleteFile(String path)Method to delete file from FTP server.InputStreamdownloadFile(String fileName)Downloads a file using the FTPClient.StringgetAddress()Getter for the fieldaddress.StringgetPassword()Getter for the fieldpassword.intgetPort()Getter for the fieldport.StringgetUsername()Getter for the fieldusername.booleanisConnected()Method 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.
-
-
-
Method Detail
-
setAddress
public void setAddress(String address)
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.
-
setUsername
public void setUsername(String username)
Setter for the field
username.- Parameters:
username- aStringobject.
-
setPassword
public void setPassword(String password)
Setter for the field
password.- Parameters:
password- aStringobject.
-
connectFTPClient
public void connectFTPClient() throws FTPException, IOExceptionCreates 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
public void closeFTPConnection() throws IOExceptionCloses a FTPClient with a connection.- Throws:
IOException- Throw if an error occurs during disconnection.
-
downloadFile
public InputStream downloadFile(String fileName) throws IOException, FTPException
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
public boolean uploadFile(File file) throws IOException, FTPException
uploadFile.
- Parameters:
file- aFileobject.- Returns:
- a boolean.
- Throws:
IOException- if any.FTPException- if any.
-
deleteFile
public boolean deleteFile(String path) throws FTPException, IOException
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.
-
-