Class FTPBean


  • public class FTPBean
    extends java.lang.Object
    This class helps to expose the functionality of the FTP Client through the scripting environment.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  FTPBean.DirectoryContents
      This class is a container in which the contents of a directory can be saved.
    • Constructor Summary

      Constructors 
      Constructor Description
      FTPBean()
      Constructor creating the FTP client object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean cd​(java.lang.String path)
      Changes the working directory.
      boolean close()
      Closes the connection of the FTP client to the server.
      boolean connect​(java.lang.String host, java.lang.String username, java.lang.String password)
      Connects to the specified FTP server using the given credentials to login.
      boolean connect​(java.lang.String host, java.lang.String username, java.lang.String password, boolean useSSLonCommandChannel, boolean useSSLonDataChannel)
      Connects to the specified FTP server using the given credentials to login.
      java.lang.Object dir()
      Returns an object representing the contents of the current working directory on the FTP server.
      boolean get​(java.lang.String remoteFile, java.lang.String localFile)
      Gets a file from the FTP server.
      boolean getDebug()
      Gets the debug level that has been set.
      java.lang.Exception getLastError()
      Returns the last exception occurred.
      boolean put​(java.lang.String localFile, java.lang.String remoteFile)
      Puts a local file on the FTP server.
      boolean remove​(java.lang.String path)
      Deletes the given file/directory from the FTP server.
      boolean rename​(java.lang.String fromPath, java.lang.String toPath)
      Renames the given file/directory on the FTP server.
      void setAscii()
      Sets ASCII transfer mode.
      void setBinary()
      Sets binary transfer mode.
      void setDebug​(boolean debug)
      Sets the debug level of the FTP client.
      boolean setLastErr​(java.lang.Exception e)
      Sets the passed as parameter exception as the last exception of the FTP client so far.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FTPBean

        public FTPBean()
        Constructor creating the FTP client object.
    • Method Detail

      • connect

        public boolean connect​(java.lang.String host,
                               java.lang.String username,
                               java.lang.String password)
        Connects to the specified FTP server using the given credentials to login. No SSL security is used for the data and control channels created.
        Parameters:
        host - the host of the FTP server.
        username - the username used to login.
        password - the password used to login.
        Returns:
        true if no exception occurs, otherwise false.
      • connect

        public boolean connect​(java.lang.String host,
                               java.lang.String username,
                               java.lang.String password,
                               boolean useSSLonCommandChannel,
                               boolean useSSLonDataChannel)
        Connects to the specified FTP server using the given credentials to login. The usage of SSL on the data and control channels is specified by the last two parameters.
        Parameters:
        host - the host of the FTP server.
        username - the username used to login.
        password - the password used to login.
        useSSLonCommandChannel - whether to use SSL on the control channel.
        useSSLonDataChannel - whether to use SSL on the data channel.
        Returns:
        true if no exception occurs, otherwise false.
      • close

        public boolean close()
        Closes the connection of the FTP client to the server.
        Returns:
        true if no exception occurred, otherwise false.
      • setBinary

        public void setBinary()
        Sets binary transfer mode.
      • setAscii

        public void setAscii()
        Sets ASCII transfer mode.
      • get

        public boolean get​(java.lang.String remoteFile,
                           java.lang.String localFile)
        Gets a file from the FTP server.
        Parameters:
        remoteFile - the file to be retrieved from the server.
        localFile - the name used to save the file on the local machine.
        Returns:
        true if no exception occurs, otherwise false.
      • put

        public boolean put​(java.lang.String localFile,
                           java.lang.String remoteFile)
        Puts a local file on the FTP server.
        Parameters:
        localFile - the local file to be sent to the server.
        remoteFile - the name used for saving the file on the server.
        Returns:
        true if no exception occurs, otherwise false.
      • cd

        public boolean cd​(java.lang.String path)
        Changes the working directory.
        Parameters:
        path - the new working directory.
        Returns:
        true if no exception occurs, otherwise false.
      • dir

        public java.lang.Object dir()
        Returns an object representing the contents of the current working directory on the FTP server.
        Returns:
        the current working directory contents.
      • remove

        public boolean remove​(java.lang.String path)
        Deletes the given file/directory from the FTP server.
        Parameters:
        path - the path of the file/directory to be removed.
        Returns:
        true if no exception occurs, otherwise false.
      • rename

        public boolean rename​(java.lang.String fromPath,
                              java.lang.String toPath)
        Renames the given file/directory on the FTP server.
        Parameters:
        fromPath - old name.
        toPath - new name.
        Returns:
        true if no exception occurs, otherwise false.
      • setLastErr

        public boolean setLastErr​(java.lang.Exception e)
        Sets the passed as parameter exception as the last exception of the FTP client so far.
        Parameters:
        e - an exception.
        Returns:
        true if the given exception is null, otherwise false.
      • getLastError

        public java.lang.Exception getLastError()
        Returns the last exception occurred.
        Returns:
        the last occurred exception.
      • setDebug

        public void setDebug​(boolean debug)
        Sets the debug level of the FTP client.
        Parameters:
        debug - if true detailed logging will be used, otherwise no.
      • getDebug

        public boolean getDebug()
        Gets the debug level that has been set.
        Returns:
        true if detailed logging is used, otherwise false.