Class 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.
    • Constructor Detail

      • FTPClient

        public FTPClient​(String address)

        Constructor for FTPClient.

        Parameters:
        address - a String object.
    • Method Detail

      • getAddress

        public String getAddress()

        Getter for the field address.

        Returns:
        a String object.
      • setAddress

        public void setAddress​(String address)

        Setter for the field address.

        Parameters:
        address - a String 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

        public String getUsername()

        Getter for the field username.

        Returns:
        a String object.
      • setUsername

        public void setUsername​(String username)

        Setter for the field username.

        Parameters:
        username - a String object.
      • getPassword

        public String getPassword()

        Getter for the field password.

        Returns:
        a String object.
      • setPassword

        public void setPassword​(String password)

        Setter for the field password.

        Parameters:
        password - a String object.
      • connectFTPClient

        public void connectFTPClient()
                              throws FTPException,
                                     IOException
        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

        public void closeFTPConnection()
                                throws IOException
        Closes 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 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.
      • 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 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.