Class VsftpRepository

  • All Implemented Interfaces:
    Repository

    public class VsftpRepository
    extends AbstractRepository
    Repository using SecureCRT vsftp command line program to access an sftp repository This is especially useful to leverage the gssapi authentication supported by SecureCRT. In cases where usual sftp is enough, prefer the 100% java solution of sftp repository. This requires SecureCRT to be in the PATH. Tested with SecureCRT 5.0.5
    • Constructor Detail

      • VsftpRepository

        public VsftpRepository()
    • Method Detail

      • getResource

        public Resource getResource​(java.lang.String source)
                             throws java.io.IOException
        Description copied from interface: Repository
        Return the resource associated with a specified identifier. If the resource does not exist, it should return a Resource with exists() returning false. An IOException should only be thrown when a real IO problem occurs, like the impossibility to connect to a server.
        Parameters:
        source - A string identifying the resource.
        Returns:
        The resource associated with the resource identifier.
        Throws:
        java.io.IOException - On error while trying to get resource.
      • getInitResource

        protected Resource getInitResource​(java.lang.String source)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • get

        public void get​(java.lang.String source,
                        java.io.File destination)
                 throws java.io.IOException
        Description copied from interface: Repository
        Fetch a resource from the repository.
        Parameters:
        source - A string identifying the resource to be fetched.
        destination - Where to place the fetched resource.
        Throws:
        java.io.IOException - On retrieval failure.
      • list

        public java.util.List<java.lang.String> list​(java.lang.String parent)
                                              throws java.io.IOException
        Description copied from interface: Repository
        Return a listing of resources names
        Parameters:
        parent - The parent directory from which to generate the listing.
        Returns:
        A listing of the parent directory's file content
        Throws:
        java.io.IOException - On listing failure.
      • put

        public void put​(java.io.File source,
                        java.lang.String destination,
                        boolean overwrite)
                 throws java.io.IOException
        Overrides:
        put in class AbstractRepository
        Throws:
        java.io.IOException
      • sendCommand

        protected java.lang.String sendCommand​(java.lang.String command)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • sendCommand

        protected void sendCommand​(java.lang.String command,
                                   java.util.regex.Pattern expectedResponse)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • sendCommand

        protected void sendCommand​(java.lang.String command,
                                   java.util.regex.Pattern expectedResponse,
                                   long timeout)
                            throws java.io.IOException
        The behaviour of vsftp with some commands is to log the resulting message on the error stream, even if everything is ok. So it's quite difficult if there was an error or not. Hence we compare the response with the expected message and deal with it. The problem is that this is very specific to the version of vsftp used for the test, That's why expected messages are obtained using overriddable protected methods.
        Parameters:
        command - String
        expectedResponse - Pattern
        timeout - long
        Throws:
        java.io.IOException - if something goes wrong
      • sendCommand

        protected java.lang.String sendCommand​(java.lang.String command,
                                               boolean sendErrorAsResponse)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • sendCommand

        protected java.lang.String sendCommand​(java.lang.String command,
                                               boolean sendErrorAsResponse,
                                               boolean single)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • sendCommand

        protected java.lang.String sendCommand​(java.lang.String command,
                                               boolean sendErrorAsResponse,
                                               long timeout)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • sendCommand

        protected java.lang.String sendCommand​(java.lang.String command,
                                               boolean sendErrorAsResponse,
                                               boolean single,
                                               long timeout)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • readResponse

        protected java.lang.String readResponse​(boolean sendErrorAsResponse)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • readResponse

        protected java.lang.String readResponse​(boolean sendErrorAsResponse,
                                                long timeout)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • ensureConnectionOpened

        protected void ensureConnectionOpened()
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • disconnect

        public void disconnect()
      • lslToResource

        protected Resource lslToResource​(java.lang.String file,
                                         java.lang.String responseLine)
        Parses a ls -l line and transforms it in a resource
        Parameters:
        file - ditto
        responseLine - ditto
        Returns:
        Resource
      • getSingleCommand

        protected java.lang.String getSingleCommand​(java.lang.String command)
      • getConnectionCommand

        protected java.lang.String getConnectionCommand()
      • getExpectedDownloadMessage

        protected java.util.regex.Pattern getExpectedDownloadMessage​(java.lang.String source,
                                                                     java.io.File to)
      • getExpectedRemoveMessage

        protected java.util.regex.Pattern getExpectedRemoveMessage​(java.lang.String destination)
      • getExpectedUploadMessage

        protected java.util.regex.Pattern getExpectedUploadMessage​(java.io.File source,
                                                                   java.lang.String to)
      • getAuthentication

        public java.lang.String getAuthentication()
      • setAuthentication

        public void setAuthentication​(java.lang.String authentication)
      • getHost

        public java.lang.String getHost()
      • setHost

        public void setHost​(java.lang.String host)
      • getUsername

        public java.lang.String getUsername()
      • setUsername

        public void setUsername​(java.lang.String username)
      • setReuseConnection

        public void setReuseConnection​(long time)
        Sets the reuse connection time. The same connection will be reused if the time here does not last between two commands. O indicates that the connection should never be reused
        Parameters:
        time - long
      • getReadTimeout

        public long getReadTimeout()
      • setReadTimeout

        public void setReadTimeout​(long readTimeout)