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 TypeMethodDescriptionvoid
Closes a FTPClient with a connection.void
Creates a FTPClient with a connection given using credentials from the FTPServer object.boolean
deleteFile
(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
.int
getPort()
Getter for the fieldport
.Getter for the fieldusername
.boolean
Method to check if there is an active conenction to the FTP Servervoid
setAddress
(String address) Setter for the fieldaddress
.void
setPassword
(String password) Setter for the fieldpassword
.void
setPort
(int port) Setter for the fieldport
.void
setUsername
(String username) Setter for the fieldusername
.boolean
uploadFile
(File file) uploadFile.boolean
uploadFile
(String localFilePath, String remoteFileName) Uploads a file to the FTp Server.
-
Constructor Details
-
FTPClient
Constructor for FTPClient.
- Parameters:
address
- aString
object.
-
-
Method Details
-
getAddress
Getter for the field
address
.- Returns:
- a
String
object.
-
setAddress
Setter for the field
address
.- Parameters:
address
- aString
object.
-
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
String
object.
-
setUsername
Setter for the field
username
.- Parameters:
username
- aString
object.
-
getPassword
Getter for the field
password
.- Returns:
- a
String
object.
-
setPassword
Setter for the field
password
.- Parameters:
password
- aString
object.
-
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
InputStream
containing 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
Boolean
true 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
- aFile
object.- 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
Boolean
true 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
Boolean
true if connected, false otherwise.
-