Class JSch


  • public class JSch
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String VERSION
      The version number.
    • Constructor Summary

      Constructors 
      Constructor Description
      JSch()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void addIdentity​(Identity identity, byte[] passphrase)
      Sets the private key, which will be referred in the public key authentication.
      void addIdentity​(java.lang.String prvkey)
      Sets the private key, which will be referred in the public key authentication.
      void addIdentity​(java.lang.String prvkey, byte[] passphrase)
      Sets the private key, which will be referred in the public key authentication.
      void addIdentity​(java.lang.String name, byte[] prvkey, byte[] pubkey, byte[] passphrase)
      Sets the private key, which will be referred in the public key authentication.
      void addIdentity​(java.lang.String prvkey, java.lang.String passphrase)
      Sets the private key, which will be referred in the public key authentication.
      void addIdentity​(java.lang.String prvkey, java.lang.String pubkey, byte[] passphrase)
      Sets the private key, which will be referred in the public key authentication.
      protected void addSession​(Session session)  
      static java.lang.String getConfig​(java.lang.String key)
      Returns the config value for the specified key.
      ConfigRepository getConfigRepository()  
      HostKeyRepository getHostKeyRepository()
      Returns the current hostkey repository.
      java.util.Vector<java.lang.String> getIdentityNames()
      Lists names of identities included in the identityRepository.
      IdentityRepository getIdentityRepository()  
      Logger getInstanceLogger()
      Returns a logger to be used for this particular instance of JSch
      static Logger getLogger()
      Returns the statically set logger, i.e.
      Session getSession​(java.lang.String host)
      Instantiates the Session object with host.
      Session getSession​(java.lang.String username, java.lang.String host)
      Instantiates the Session object with username and host.
      Session getSession​(java.lang.String username, java.lang.String host, int port)
      Instantiates the Session object with given username, host and port.
      void removeAllIdentity()
      Removes all identities from identityRepository.
      void removeIdentity​(Identity identity)
      Removes the identity from identityRepository.
      void removeIdentity​(java.lang.String name)
      Deprecated.
      use #removeIdentity(Identity identity)
      protected boolean removeSession​(Session session)  
      static void setConfig​(java.lang.String key, java.lang.String value)
      Sets or Overrides the configuration.
      static void setConfig​(java.util.Hashtable<java.lang.String,​java.lang.String> newconf)
      Sets or Overrides the configuration.
      void setConfigRepository​(ConfigRepository configRepository)  
      void setHostKeyRepository​(HostKeyRepository hkrepo)
      Sets the hostkey repository.
      void setIdentityRepository​(IdentityRepository identityRepository)
      Sets the identityRepository, which will be referred in the public key authentication.
      void setInstanceLogger​(Logger logger)
      Sets a logger to be used for this particular instance of JSch
      void setKnownHosts​(java.io.InputStream stream)
      Sets the instance of KnownHosts generated with stream.
      void setKnownHosts​(java.lang.String filename)
      Sets the instance of KnownHosts, which refers to filename.
      static void setLogger​(Logger logger)
      Sets the logger
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • VERSION

        public static final java.lang.String VERSION
        The version number.
    • Constructor Detail

      • JSch

        public JSch()
    • Method Detail

      • setIdentityRepository

        public void setIdentityRepository​(IdentityRepository identityRepository)
        Sets the identityRepository, which will be referred in the public key authentication.
        Parameters:
        identityRepository - if null is given, the default repository, which usually refers to ~/.ssh/, will be used.
        See Also:
        getIdentityRepository()
      • setConfigRepository

        public void setConfigRepository​(ConfigRepository configRepository)
      • getSession

        public Session getSession​(java.lang.String username,
                                  java.lang.String host)
                           throws JSchException
        Instantiates the Session object with username and host. The TCP port 22 will be used in making the connection. Note that the TCP connection must not be established until Session#connect().
        Parameters:
        username - user name
        host - hostname
        Returns:
        the instance of Session class.
        Throws:
        JSchException - if username or host are invalid.
        See Also:
        getSession(String username, String host, int port), Session
      • getSession

        public Session getSession​(java.lang.String username,
                                  java.lang.String host,
                                  int port)
                           throws JSchException
        Instantiates the Session object with given username, host and port. Note that the TCP connection must not be established until Session#connect().
        Parameters:
        username - user name
        host - hostname
        port - port number
        Returns:
        the instance of Session class.
        Throws:
        JSchException - if username or host are invalid.
        See Also:
        getSession(String username, String host, int port), Session
      • addSession

        protected void addSession​(Session session)
      • removeSession

        protected boolean removeSession​(Session session)
      • setHostKeyRepository

        public void setHostKeyRepository​(HostKeyRepository hkrepo)
        Sets the hostkey repository.
        Parameters:
        hkrepo -
        See Also:
        HostKeyRepository, KnownHosts
      • setKnownHosts

        public void setKnownHosts​(java.lang.String filename)
                           throws JSchException
        Sets the instance of KnownHosts, which refers to filename.
        Parameters:
        filename - filename of known_hosts file.
        Throws:
        JSchException - if the given filename is invalid.
        See Also:
        KnownHosts
      • setKnownHosts

        public void setKnownHosts​(java.io.InputStream stream)
                           throws JSchException
        Sets the instance of KnownHosts generated with stream.
        Parameters:
        stream - the instance of InputStream from known_hosts file.
        Throws:
        JSchException - if an I/O error occurs.
        See Also:
        KnownHosts
      • getHostKeyRepository

        public HostKeyRepository getHostKeyRepository()
        Returns the current hostkey repository. By the default, this method will the instance of KnownHosts.
        Returns:
        current hostkey repository.
        See Also:
        HostKeyRepository, KnownHosts
      • addIdentity

        public void addIdentity​(java.lang.String prvkey,
                                java.lang.String passphrase)
                         throws JSchException
        Sets the private key, which will be referred in the public key authentication. Before registering it into identityRepository, it will be deciphered with passphrase.
        Parameters:
        prvkey - filename of the private key.
        passphrase - passphrase for prvkey.
        Throws:
        JSchException - if passphrase is not right.
        See Also:
        addIdentity(String prvkey, byte[] passphrase)
      • addIdentity

        public void addIdentity​(java.lang.String prvkey,
                                byte[] passphrase)
                         throws JSchException
        Sets the private key, which will be referred in the public key authentication. Before registering it into identityRepository, it will be deciphered with passphrase.
        Parameters:
        prvkey - filename of the private key.
        passphrase - passphrase for prvkey.
        Throws:
        JSchException - if passphrase is not right.
        See Also:
        addIdentity(String prvkey, String pubkey, byte[] passphrase)
      • addIdentity

        public void addIdentity​(java.lang.String prvkey,
                                java.lang.String pubkey,
                                byte[] passphrase)
                         throws JSchException
        Sets the private key, which will be referred in the public key authentication. Before registering it into identityRepository, it will be deciphered with passphrase.
        Parameters:
        prvkey - filename of the private key.
        pubkey - filename of the public key.
        passphrase - passphrase for prvkey.
        Throws:
        JSchException - if passphrase is not right.
      • addIdentity

        public void addIdentity​(java.lang.String name,
                                byte[] prvkey,
                                byte[] pubkey,
                                byte[] passphrase)
                         throws JSchException
        Sets the private key, which will be referred in the public key authentication. Before registering it into identityRepository, it will be deciphered with passphrase.
        Parameters:
        name - name of the identity to be used to retrieve it in the identityRepository.
        prvkey - private key in byte array.
        pubkey - public key in byte array.
        passphrase - passphrase for prvkey.
        Throws:
        JSchException
      • addIdentity

        public void addIdentity​(Identity identity,
                                byte[] passphrase)
                         throws JSchException
        Sets the private key, which will be referred in the public key authentication. Before registering it into identityRepository, it will be deciphered with passphrase.
        Parameters:
        identity - private key.
        passphrase - passphrase for identity.
        Throws:
        JSchException - if passphrase is not right.
      • removeIdentity

        @Deprecated
        public void removeIdentity​(java.lang.String name)
                            throws JSchException
        Deprecated.
        use #removeIdentity(Identity identity)
        Throws:
        JSchException
      • removeIdentity

        public void removeIdentity​(Identity identity)
                            throws JSchException
        Removes the identity from identityRepository.
        Parameters:
        identity - the indentity to be removed.
        Throws:
        JSchException - if identity is invalid.
      • getIdentityNames

        public java.util.Vector<java.lang.String> getIdentityNames()
                                                            throws JSchException
        Lists names of identities included in the identityRepository.
        Returns:
        names of identities
        Throws:
        JSchException - if identityReposory has problems.
      • removeAllIdentity

        public void removeAllIdentity()
                               throws JSchException
        Removes all identities from identityRepository.
        Throws:
        JSchException - if identityReposory has problems.
      • getConfig

        public static java.lang.String getConfig​(java.lang.String key)
        Returns the config value for the specified key.
        Parameters:
        key - key for the configuration.
        Returns:
        config value
      • setConfig

        public static void setConfig​(java.util.Hashtable<java.lang.String,​java.lang.String> newconf)
        Sets or Overrides the configuration.
        Parameters:
        newconf - configurations
      • setConfig

        public static void setConfig​(java.lang.String key,
                                     java.lang.String value)
        Sets or Overrides the configuration.
        Parameters:
        key - key for the configuration
        value - value for the configuration
      • setLogger

        public static void setLogger​(Logger logger)
        Sets the logger
        Parameters:
        logger - logger or null if no logging should take place
        See Also:
        Logger
      • getInstanceLogger

        public Logger getInstanceLogger()
        Returns a logger to be used for this particular instance of JSch
        Returns:
        The logger that is used by this instance. If no particular logger has been set, the statically set logger is returned.
      • setInstanceLogger

        public void setInstanceLogger​(Logger logger)
        Sets a logger to be used for this particular instance of JSch
        Parameters:
        logger - The logger to be used or null if the statically set logger should be used
      • getLogger

        public static Logger getLogger()
        Returns the statically set logger, i.e. the logger being used by all JSch instances without explicitly set logger.
        Returns:
        The logger