Class SftpDirectoryLister

    • Field Detail

      • m_Host

        protected String m_Host
        the SSH host.
      • m_Port

        protected int m_Port
        the SSH port.
      • m_AuthenticationType

        protected SSHAuthenticationType m_AuthenticationType
        the type of authentication to use.
      • m_User

        protected String m_User
        the SSH user to use.
      • m_Password

        protected BasePassword m_Password
        the SSH password to use.
      • m_PrivateKeyFile

        protected PlaceholderFile m_PrivateKeyFile
        the location of the private key.
      • m_PrivateKeyPassphrase

        protected BasePassword m_PrivateKeyPassphrase
        the passphrase for the private key.
      • m_KnownHosts

        protected PlaceholderFile m_KnownHosts
        the file with known hosts.
      • m_StrictHostKeyChecking

        protected boolean m_StrictHostKeyChecking
        whether to perform strict host key checking (only disable for testing!! insecure!!).
      • m_SessionProvider

        protected SSHSessionProvider m_SessionProvider
        the session provider to use.
      • m_Session

        protected transient com.jcraft.jsch.Session m_Session
        the SSH session.
    • Constructor Detail

      • SftpDirectoryLister

        public SftpDirectoryLister()
    • Method Detail

      • setHost

        public void setHost​(String value)
        Sets the host to connect to.
        Parameters:
        value - the host name/ip
      • getHost

        public String getHost()
        Returns the host to connect to.
        Returns:
        the host name/ip
      • setPort

        public void setPort​(int value)
        Sets the port to connect to.
        Parameters:
        value - the port
      • getPort

        public int getPort()
        Returns the port to connect to.
        Returns:
        the port
      • setAuthenticationType

        public void setAuthenticationType​(SSHAuthenticationType value)
        Sets the type of authentication to use.
        Parameters:
        value - the type
      • getAuthenticationType

        public SSHAuthenticationType getAuthenticationType()
        Returns the type of authentication to use.
        Returns:
        the type
      • setUser

        public void setUser​(String value)
        Sets the SSH user to use.
        Parameters:
        value - the user name
      • getUser

        public String getUser()
        Returns the SSH user name to use.
        Returns:
        the user name
      • setPrivateKeyFile

        public void setPrivateKeyFile​(PlaceholderFile value)
        Sets the location of the private key file.
        Parameters:
        value - the key file
      • getPrivateKeyFile

        public PlaceholderFile getPrivateKeyFile()
        Returns the location of the private key file.
        Returns:
        the key file
      • setPrivateKeyPassphrase

        public void setPrivateKeyPassphrase​(BasePassword value)
        Sets the passphrase for the private key file, ignored if empty.
        Parameters:
        value - the passphrase
      • getPrivateKeyPassphrase

        public BasePassword getPrivateKeyPassphrase()
        Returns the passphrase for the private key file, ignored if empty.
        Returns:
        the passphrase
      • setKnownHosts

        public void setKnownHosts​(PlaceholderFile value)
        Sets the file with the known hosts.
        Parameters:
        value - the file
      • getKnownHosts

        public PlaceholderFile getKnownHosts()
        Returns the file with the known hosts.
        Returns:
        the file
      • setStrictHostKeyChecking

        public void setStrictHostKeyChecking​(boolean value)
        Sets whether to perform strict host key checking. NB: only disabled for testing, as it is very insecure to disable it!
        Parameters:
        value - if true then strict checking is on
      • getStrictHostKeyChecking

        public boolean getStrictHostKeyChecking()
        Returns whether to perform strict host key checking. NB: only disabled for testing, as it is very insecure to disable it!
        Returns:
        true if strict checking is on
      • setSessionProvider

        public void setSessionProvider​(SSHSessionProvider value)
        Sets the session provider to use.
        Parameters:
        value - the session provider
      • getSessionProvider

        public SSHSessionProvider getSessionProvider()
        Returns the current session provider.
        Returns:
        the provider, null if none set
      • newSession

        protected com.jcraft.jsch.Session newSession()
        Returns a new session for the host/port defined in the options.
        Returns:
        the session
      • newSession

        protected com.jcraft.jsch.Session newSession​(String host,
                                                     int port)
        Returns a new session for the given host/port.
        Parameters:
        host - the host to create the session for
        Returns:
        the session
      • disconnect

        protected void disconnect()
        Disconnects the SSH session, if necessary.
      • isLocal

        public boolean isLocal()
        Returns whether the directory lister operates locally or remotely.
        Specified by:
        isLocal in interface DirectoryLister
        Returns:
        true if local lister
      • hasParentDirectory

        public boolean hasParentDirectory()
        Returns whether the watch directory has a parent directory.
        Specified by:
        hasParentDirectory in interface DirectoryLister
        Returns:
        true if parent directory available
      • newDirectory

        public SftpFileObject newDirectory​(String dir)
        Returns a new directory relative to the watch directory.
        Specified by:
        newDirectory in interface DirectoryLister
        Parameters:
        dir - the directory name
        Returns:
        the new wrapper
      • newDirectory

        public SftpFileObject newDirectory​(String parent,
                                           String dir)
        Returns a new directory generated from parent and sub-directory.
        Specified by:
        newDirectory in interface DirectoryLister
        Parameters:
        parent - the parent directory
        dir - the directory name
        Returns:
        the new wrapper
      • search

        protected void search​(com.jcraft.jsch.ChannelSftp channel,
                              String current,
                              List<SortContainer> files,
                              int depth)
                       throws Exception
        Performs the recursive search. Search goes deeper if != 0 (use -1 to start with for infinite search).
        Parameters:
        channel - the SFTP channel to use
        current - the current directory
        files - the files collected so far
        depth - the depth indicator (searched no deeper, if 0)
        Throws:
        Exception - if listing fails
      • search

        public List<SftpFileObject> search​(com.jcraft.jsch.ChannelSftp channel)
                                    throws Exception
        Returns the list of files/directories in the watched directory. In case the execution gets stopped, this method returns a 0-length array.
        Parameters:
        channel - the SFTP channel to use
        Returns:
        the list of absolute file/directory names
        Throws:
        Exception - if listing fails
      • list

        public String[] list()
        Returns the list of files/directories in the watched directory. In case the execution gets stopped, this method returns a 0-length array.
        Specified by:
        list in interface DirectoryLister
        Returns:
        the list of absolute file/directory names
      • listObjects

        public SftpFileObject[] listObjects()
        Returns the list of files/directories in the watched directory. In case the execution gets stopped, this method returns a 0-length array.
        Specified by:
        listObjects in interface DirectoryLister
        Returns:
        the list of file/directory wrappers