Interface FileTransferClient

    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      void chdir​(java.lang.String dir)
      Change the remote working directory to that supplied
      default void close()  
      void connect​(java.lang.String user, java.lang.String password)
      Connect and login into an account on the FTP server.
      void delete​(java.lang.String remoteFile)
      Delete the specified remote file
      default java.lang.String[] dir()
      List current directory's contents as an array of strings of filenames.
      default java.lang.String[] dir​(java.lang.String dirname)
      List a directory's contents as an array of strings of filenames.
      java.lang.String[] dir​(java.lang.String dirname, boolean full)
      List a directory's contents as an array of strings.
      java.lang.String[] dir​(java.lang.String directory, java.io.FileFilter filter)
      List a directory's contents
      void disconnect()
      Quit the FTP session
      void get​(java.io.OutputStream destStream, java.lang.String remoteFile)
      Get data from the FTP server.
      byte[] get​(java.lang.String remoteFile)
      Get data from the FTP server.
      default void get​(java.lang.String localPath, java.lang.String remoteFile)
      Get data from the FTP server.
      long getKeepAliveTimeout()
      Get the time to wait between sending control connection keepalive messages.
      boolean isConnected()
      Check if this client is still connected to its target Any errors return a false This is used to check cached connections are still working
      boolean isDirectory​(java.lang.String path)  
      long lastModified​(java.lang.String path)
      Return the last modified time for the given path.
      java.util.Date lastModifiedDate​(java.lang.String path)
      Return the last modified date for the given path.
      void mkdir​(java.lang.String dir)
      Create the specified remote working directory
      default void put​(byte[] bytes, java.lang.String remoteFile)
      Put data onto the FTP server.
      default void put​(byte[] bytes, java.lang.String remoteFile, boolean append)
      Put data onto the FTP server.
      default void put​(java.io.InputStream srcStream, java.lang.String remoteFile)
      Put a stream of data onto the FTP server.
      void put​(java.io.InputStream srcStream, java.lang.String remoteFile, boolean append)
      Put a stream of data onto the FTP server.
      default void put​(java.lang.String localPath, java.lang.String remoteFile)
      Put a local file onto the FTP server.
      default void put​(java.lang.String localPath, java.lang.String remoteFile, boolean append)
      Put a local file onto the FTP server.
      void rename​(java.lang.String from, java.lang.String to)
      Rename a file or directory
      void rmdir​(java.lang.String dir)
      Delete the specified remote working directory
      void setAdditionalDebug​(boolean b)
      Switch additional debug on or off
      void setKeepAliveTimeout​(long seconds)
      Set the time to wait between sending control connection keepalive messages when processing file upload or download.
    • Method Detail

      • connect

        void connect​(java.lang.String user,
                     java.lang.String password)
              throws java.io.IOException,
                     FileTransferException
        Connect and login into an account on the FTP server. This completes the entire login process
        Parameters:
        user - user name
        password - user's password
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
      • put

        default void put​(java.lang.String localPath,
                         java.lang.String remoteFile)
                  throws java.io.IOException,
                         FileTransferException
        Put a local file onto the FTP server.
        Parameters:
        remoteFile - name of remote file in current directory
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
        Implementation Note:
        The default implementation calls put(String, String, boolean) with append=false.
      • put

        default void put​(java.io.InputStream srcStream,
                         java.lang.String remoteFile)
                  throws java.io.IOException,
                         FileTransferException
        Put a stream of data onto the FTP server.
        Parameters:
        srcStream - input stream of data to put
        remoteFile - name of remote file
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
        Implementation Note:
        The default implementation calls put(String, String, boolean) with append=false.
      • put

        default void put​(java.lang.String localPath,
                         java.lang.String remoteFile,
                         boolean append)
                  throws java.io.IOException,
                         FileTransferException
        Put a local file onto the FTP server.
        Parameters:
        localPath - path of the local file
        remoteFile - name of remote file
        append - true if appending, false otherwise
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
        Implementation Note:
        The default implementation calls put(InputStream, String, boolean) with append=false.
      • put

        void put​(java.io.InputStream srcStream,
                 java.lang.String remoteFile,
                 boolean append)
          throws java.io.IOException,
                 FileTransferException
        Put a stream of data onto the FTP server.
        Parameters:
        srcStream - input stream of data to put
        remoteFile - name of remote file
        append - true if appending, false otherwise
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
      • put

        default void put​(byte[] bytes,
                         java.lang.String remoteFile)
                  throws java.io.IOException,
                         FileTransferException
        Put data onto the FTP server.
        Parameters:
        bytes - array of bytes
        remoteFile - name of remote file
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
        Implementation Note:
        The default implementation calls put(InputStream, String, boolean) with append=false.
      • put

        default void put​(byte[] bytes,
                         java.lang.String remoteFile,
                         boolean append)
                  throws java.io.IOException,
                         FileTransferException
        Put data onto the FTP server.
        Parameters:
        bytes - array of bytes
        remoteFile - name of remote file
        append - true if appending, false otherwise
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
        Implementation Note:
        The default implementation calls put(InputStream, String, boolean).
      • get

        default void get​(java.lang.String localPath,
                         java.lang.String remoteFile)
                  throws java.io.IOException,
                         FileTransferException
        Get data from the FTP server.
        Parameters:
        localPath - local file to put data in
        remoteFile - name of remote file
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
        Implementation Note:
        The default implementation calls get(OutputStream, String).
      • get

        void get​(java.io.OutputStream destStream,
                 java.lang.String remoteFile)
          throws java.io.IOException,
                 FileTransferException
        Get data from the FTP server.
        Parameters:
        destStream - data stream to write data to
        remoteFile - name of remote file
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
      • get

        byte[] get​(java.lang.String remoteFile)
            throws java.io.IOException,
                   FileTransferException
        Get data from the FTP server.
        Parameters:
        remoteFile - name of remote file
        Returns:
        a byte array.
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
      • dir

        default java.lang.String[] dir()
                                throws java.io.IOException,
                                       FileTransferException
        List current directory's contents as an array of strings of filenames.
        Returns:
        an array of current directory listing strings
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
        Implementation Note:
        The default implementation calls dir(String, boolean) with dirname=null, full=false.
      • dir

        default java.lang.String[] dir​(java.lang.String dirname)
                                throws java.io.IOException,
                                       FileTransferException
        List a directory's contents as an array of strings of filenames.
        Parameters:
        dirname - name of directory(not a file mask)
        Returns:
        an array of directory listing strings
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
        Implementation Note:
        The default implementation calls dir(String, boolean) with full=false.
      • dir

        java.lang.String[] dir​(java.lang.String dirname,
                               boolean full)
                        throws java.io.IOException,
                               FileTransferException
        List a directory's contents as an array of strings.

        A detailed listing is available, otherwise just filenames are provided. The detailed listing varies in details depending on OS and FTP server. Note that a full listing can be used on a file name to obtain information about a file. The special files "." and ".." are ignored.

        Parameters:
        dirname - name of directory (not a file mask)
        full - true if detailed listing required false otherwise
        Returns:
        an array of directory listing strings
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
      • dir

        java.lang.String[] dir​(java.lang.String directory,
                               java.io.FileFilter filter)
                        throws FileTransferException,
                               java.io.IOException
        List a directory's contents

        Note that although we use a standard FileFilter interface here operating on File; it actually uses RemoteFile instead which overrides information that can be obtained from the remote server. Other standard File operations will not be supported, and may ultimately cause a runtime exception.

        Parameters:
        directory - the directory to list.
        filter - the filefilter mask to use
        Returns:
        an array of strings containing the listing
        Throws:
        java.io.IOException - on comms error.
        FileTransferException - on FTP Specific exception error.
      • delete

        void delete​(java.lang.String remoteFile)
             throws java.io.IOException,
                    FileTransferException
        Delete the specified remote file
        Parameters:
        remoteFile - name of remote file to delete
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
      • rename

        void rename​(java.lang.String from,
                    java.lang.String to)
             throws java.io.IOException,
                    FileTransferException
        Rename a file or directory
        Parameters:
        from - name of file or directory to rename
        to - intended name
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
      • rmdir

        void rmdir​(java.lang.String dir)
            throws java.io.IOException,
                   FileTransferException
        Delete the specified remote working directory
        Parameters:
        dir - name of remote directory to delete
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
      • mkdir

        void mkdir​(java.lang.String dir)
            throws java.io.IOException,
                   FileTransferException
        Create the specified remote working directory
        Parameters:
        dir - name of remote directory to create
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
      • chdir

        void chdir​(java.lang.String dir)
            throws java.io.IOException,
                   FileTransferException
        Change the remote working directory to that supplied
        Parameters:
        dir - name of remote directory to change to
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
      • isDirectory

        boolean isDirectory​(java.lang.String path)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • disconnect

        void disconnect()
                 throws java.io.IOException,
                        FileTransferException
        Quit the FTP session
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
      • lastModified

        long lastModified​(java.lang.String path)
                   throws java.io.IOException,
                          FileTransferException
        Return the last modified time for the given path.
        Parameters:
        path - the path to the filename.
        Returns:
        the last modified time
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
      • lastModifiedDate

        java.util.Date lastModifiedDate​(java.lang.String path)
                                 throws java.io.IOException,
                                        FileTransferException
        Return the last modified date for the given path.
        Parameters:
        path - the path to the filename.
        Returns:
        the date.
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
      • setKeepAliveTimeout

        void setKeepAliveTimeout​(long seconds)
                          throws FileTransferException
        Set the time to wait between sending control connection keepalive messages when processing file upload or download.
        Parameters:
        seconds - time in seconds
        Throws:
        FileTransferException
      • isConnected

        boolean isConnected()
        Check if this client is still connected to its target Any errors return a false This is used to check cached connections are still working
        Returns:
        true = connected, false = not connected or some error
      • setAdditionalDebug

        void setAdditionalDebug​(boolean b)
        Switch additional debug on or off
        Parameters:
        b - set to true if you wish to get some additional debugging in the log file, defaults to false
      • close

        default void close()
                    throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException