Class SshSessionFactory

  • Direct Known Subclasses:
    JschConfigSessionFactory, SshdSessionFactory

    public abstract class SshSessionFactory
    extends Object
    Creates and destroys SSH connections to a remote system.

    Different implementations of the session factory may be used to control communicating with the end-user as well as reading their personal SSH configuration settings, such as known hosts and private keys.

    A RemoteSession must be returned to the factory that created it. Callers are encouraged to retain the SshSessionFactory for the duration of the period they are using the session.

    • Constructor Detail

      • SshSessionFactory

        public SshSessionFactory()
    • Method Detail

      • getInstance

        public static SshSessionFactory getInstance()
        Gets the currently configured JVM-wide factory.

        By default the factory will read from the user's $HOME/.ssh and assume OpenSSH compatibility.

        factory the current factory for this JVM.
      • setInstance

        public static void setInstance​(SshSessionFactory newFactory)
        Changes the JVM-wide factory to a different implementation.
        newFactory - factory for future sessions to be created through; if null the default factory will be restored.
      • getLocalUserName

        public static String getLocalUserName()
        Retrieves the local user name as defined by the system property "".
        the user name
      • getSession

        public abstract RemoteSession getSession​(URIish uri,
                                                 CredentialsProvider credentialsProvider,
                                                 FS fs,
                                                 int tms)
                                          throws TransportException
        Opens (or reuses) a session to a host. The returned session is connected and authenticated and is ready for further use.
        uri - URI of the remote host to connect to
        credentialsProvider - provider to support authentication, may be null if no user input for authentication is needed
        fs - the file system abstraction to use for certain file operations, such as reading configuration files
        tms - connection timeout for creating the session, in milliseconds
        a connected and authenticated session for communicating with the remote host given by the uri
        TransportException - if the session could not be created
      • getType

        public abstract String getType()
        The name of the type of session factory.
        the name of the type of session factory.