Class FTPClientWrapper

  • All Implemented Interfaces:
    FtpClient

    public class FTPClientWrapper
    extends java.lang.Object
    implements FtpClient
    A wrapper to the FTPClient to allow automatic reconnect on connection loss.

    I decided to not to use eg. noop() to determine the state of the connection to avoid unnecessary server round-trips.

    • Field Detail

      • LOG

        private static final org.apache.commons.logging.Log LOG
      • ftpClient

        private org.apache.commons.net.ftp.FTPClient ftpClient
    • Method Detail

      • abort

        public boolean abort()
                      throws java.io.IOException
        Specified by:
        abort in interface FtpClient
        Throws:
        java.io.IOException
      • appendFileStream

        public java.io.OutputStream appendFileStream​(java.lang.String relPath)
                                              throws java.io.IOException
        Specified by:
        appendFileStream in interface FtpClient
        Throws:
        java.io.IOException
      • completePendingCommand

        public boolean completePendingCommand()
                                       throws java.io.IOException
        Specified by:
        completePendingCommand in interface FtpClient
        Throws:
        java.io.IOException
      • deleteFile

        public boolean deleteFile​(java.lang.String relPath)
                           throws java.io.IOException
        Specified by:
        deleteFile in interface FtpClient
        Throws:
        java.io.IOException
      • disconnect

        public void disconnect()
                        throws java.io.IOException
        Specified by:
        disconnect in interface FtpClient
        Throws:
        java.io.IOException
      • getReplyCode

        public int getReplyCode()
                         throws java.io.IOException
        Specified by:
        getReplyCode in interface FtpClient
        Throws:
        java.io.IOException
      • getReplyString

        public java.lang.String getReplyString()
                                        throws java.io.IOException
        Specified by:
        getReplyString in interface FtpClient
        Throws:
        java.io.IOException
      • hasFeature

        public boolean hasFeature​(java.lang.String feature)
                           throws java.io.IOException
        Queries the server for a supported feature.
        Specified by:
        hasFeature in interface FtpClient
        Parameters:
        feature - the name of the feature, converted to upper case.
        Returns:
        true if the feature is present, false if the feature is not present or the FTP command failed.
        Throws:
        java.io.IOException - on error
      • listFiles

        public org.apache.commons.net.ftp.FTPFile[] listFiles​(java.lang.String relPath)
                                                       throws java.io.IOException
        Specified by:
        listFiles in interface FtpClient
        Throws:
        java.io.IOException
      • listFilesInDirectory

        private org.apache.commons.net.ftp.FTPFile[] listFilesInDirectory​(java.lang.String relPath)
                                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • makeDirectory

        public boolean makeDirectory​(java.lang.String relPath)
                              throws java.io.IOException
        Specified by:
        makeDirectory in interface FtpClient
        Throws:
        java.io.IOException
      • mdtmInstant

        public java.time.Instant mdtmInstant​(java.lang.String relPath)
                                      throws java.io.IOException
        Sends the MDTM command to get a file's date and time information after file transfer. It is typically more accurate than the "LIST" command response. Time values are always represented in UTC (GMT), and in the Gregorian calendar regardless of what calendar may have been in use at the date and time the file was last modified.

        NOTE: not all remote FTP servers support MDTM.

        Specified by:
        mdtmInstant in interface FtpClient
        Parameters:
        relPath - The relative path of the file object to execute MDTM command against
        Returns:
        new Instant object containing the MDTM timestamp.
        Throws:
        java.io.IOException - If the underlying FTP client encountered an error.
      • removeDirectory

        public boolean removeDirectory​(java.lang.String relPath)
                                throws java.io.IOException
        Specified by:
        removeDirectory in interface FtpClient
        Throws:
        java.io.IOException
      • rename

        public boolean rename​(java.lang.String oldName,
                              java.lang.String newName)
                       throws java.io.IOException
        Specified by:
        rename in interface FtpClient
        Throws:
        java.io.IOException
      • retrieveFileStream

        public java.io.InputStream retrieveFileStream​(java.lang.String relPath)
                                               throws java.io.IOException
        Specified by:
        retrieveFileStream in interface FtpClient
        Throws:
        java.io.IOException
      • retrieveFileStream

        public java.io.InputStream retrieveFileStream​(java.lang.String relPath,
                                                      int bufferSize)
                                               throws java.io.IOException
        Specified by:
        retrieveFileStream in interface FtpClient
        Throws:
        java.io.IOException
      • retrieveFileStream

        public java.io.InputStream retrieveFileStream​(java.lang.String relPath,
                                                      long restartOffset)
                                               throws java.io.IOException
        Specified by:
        retrieveFileStream in interface FtpClient
        Throws:
        java.io.IOException
      • storeFileStream

        public java.io.OutputStream storeFileStream​(java.lang.String relPath)
                                             throws java.io.IOException
        Specified by:
        storeFileStream in interface FtpClient
        Throws:
        java.io.IOException