Class Session

java.lang.Object
com.jcraft.jsch.Session
All Implemented Interfaces:
java.lang.Runnable

public class Session
extends java.lang.Object
implements java.lang.Runnable
  • Field Details

    • daemon_thread

      protected boolean daemon_thread
  • Method Details

    • connect

      public void connect() throws JSchException
      Throws:
      JSchException
    • connect

      public void connect​(int connectTimeout) throws JSchException
      Throws:
      JSchException
    • getUnavailableSignatures

      public java.lang.String[] getUnavailableSignatures()
    • rekey

      public void rekey() throws java.lang.Exception
      Throws:
      java.lang.Exception
    • openChannel

      public Channel openChannel​(java.lang.String type) throws JSchException
      Throws:
      JSchException
    • encode

      public void encode​(Packet packet) throws java.lang.Exception
      Throws:
      java.lang.Exception
    • read

      public Buffer read​(Buffer buf) throws java.lang.Exception
      Throws:
      java.lang.Exception
    • write

      public void write​(Packet packet) throws java.lang.Exception
      Throws:
      java.lang.Exception
    • run

      public void run()
      Specified by:
      run in interface java.lang.Runnable
    • disconnect

      public void disconnect()
    • setPortForwardingL

      public int setPortForwardingL​(int lport, java.lang.String host, int rport) throws JSchException
      Registers the local port forwarding for loop-back interface. If lport is 0, the tcp port will be allocated.
      Parameters:
      lport - local port for local port forwarding
      host - host address for local port forwarding
      rport - remote port number for local port forwarding
      Returns:
      an allocated local TCP port number
      Throws:
      JSchException
      See Also:
      setPortForwardingL(String bind_address, int lport, String host, int rport, ServerSocketFactory ssf, int connectTimeout)
    • setPortForwardingL

      public int setPortForwardingL​(java.lang.String bind_address, int lport, java.lang.String host, int rport) throws JSchException
      Registers the local port forwarding. If bind_address is an empty string or '*', the port should be available from all interfaces. If bind_address is "localhost" or null, the listening port will be bound for local use only. If lport is 0, the tcp port will be allocated.
      Parameters:
      bind_address - bind address for local port forwarding
      lport - local port for local port forwarding
      host - host address for local port forwarding
      rport - remote port number for local port forwarding
      Returns:
      an allocated local TCP port number
      Throws:
      JSchException
      See Also:
      setPortForwardingL(String bind_address, int lport, String host, int rport, ServerSocketFactory ssf, int connectTimeout)
    • setPortForwardingL

      public int setPortForwardingL​(java.lang.String bind_address, int lport, java.lang.String host, int rport, ServerSocketFactory ssf) throws JSchException
      Registers the local port forwarding. If bind_address is an empty string or "*", the port should be available from all interfaces. If bind_address is "localhost" or null, the listening port will be bound for local use only. If lport is 0, the tcp port will be allocated.
      Parameters:
      bind_address - bind address for local port forwarding
      lport - local port for local port forwarding
      host - host address for local port forwarding
      rport - remote port number for local port forwarding
      ssf - socket factory
      Returns:
      an allocated local TCP port number
      Throws:
      JSchException
      See Also:
      setPortForwardingL(String bind_address, int lport, String host, int rport, ServerSocketFactory ssf, int connectTimeout)
    • setPortForwardingL

      public int setPortForwardingL​(java.lang.String bind_address, int lport, java.lang.String host, int rport, ServerSocketFactory ssf, int connectTimeout) throws JSchException
      Registers the local port forwarding. If bind_address is an empty string or "*", the port should be available from all interfaces. If bind_address is "localhost" or null, the listening port will be bound for local use only. If lport is 0, the tcp port will be allocated.
      Parameters:
      bind_address - bind address for local port forwarding
      lport - local port for local port forwarding
      host - host address for local port forwarding
      rport - remote port number for local port forwarding
      ssf - socket factory
      connectTimeout - timeout for establishing port connection
      Returns:
      an allocated local TCP port number
      Throws:
      JSchException
    • setSocketForwardingL

      public int setSocketForwardingL​(java.lang.String bindAddress, int lport, java.lang.String socketPath, ServerSocketFactory ssf, int connectTimeout) throws JSchException
      Throws:
      JSchException
    • delPortForwardingL

      public void delPortForwardingL​(int lport) throws JSchException
      Cancels the local port forwarding assigned at local TCP port lport on loopback interface.
      Parameters:
      lport - local TCP port
      Throws:
      JSchException
    • delPortForwardingL

      public void delPortForwardingL​(java.lang.String bind_address, int lport) throws JSchException
      Cancels the local port forwarding assigned at local TCP port lport on bind_address interface.
      Parameters:
      bind_address - bind_address of network interfaces
      lport - local TCP port
      Throws:
      JSchException
    • getPortForwardingL

      public java.lang.String[] getPortForwardingL() throws JSchException
      Lists the registered local port forwarding.
      Returns:
      a list of "lport:host:hostport"
      Throws:
      JSchException
    • setPortForwardingR

      public void setPortForwardingR​(int rport, java.lang.String host, int lport) throws JSchException
      Registers the remote port forwarding for the loopback interface of the remote.
      Parameters:
      rport - remote port
      host - host address
      lport - local port
      Throws:
      JSchException
      See Also:
      setPortForwardingR(String bind_address, int rport, String host, int lport, SocketFactory sf)
    • setPortForwardingR

      public void setPortForwardingR​(java.lang.String bind_address, int rport, java.lang.String host, int lport) throws JSchException
      Registers the remote port forwarding. If bind_address is an empty string or "*", the port should be available from all interfaces. If bind_address is "localhost" or is not given, the listening port will be bound for local use only. Note that if GatewayPorts is "no" on the remote, "localhost" is always used as a bind_address.
      Parameters:
      bind_address - bind address
      rport - remote port
      host - host address
      lport - local port
      Throws:
      JSchException
      See Also:
      setPortForwardingR(String bind_address, int rport, String host, int lport, SocketFactory sf)
    • setPortForwardingR

      public void setPortForwardingR​(int rport, java.lang.String host, int lport, SocketFactory sf) throws JSchException
      Registers the remote port forwarding for the loopback interface of the remote.
      Parameters:
      rport - remote port
      host - host address
      lport - local port
      sf - socket factory
      Throws:
      JSchException
      See Also:
      setPortForwardingR(String bind_address, int rport, String host, int lport, SocketFactory sf)
    • setPortForwardingR

      public void setPortForwardingR​(java.lang.String bind_address, int rport, java.lang.String host, int lport, SocketFactory sf) throws JSchException
      Registers the remote port forwarding. If bind_address is an empty string or "*", the port should be available from all interfaces. If bind_address is "localhost" or is not given, the listening port will be bound for local use only. Note that if GatewayPorts is "no" on the remote, "localhost" is always used as a bind_address. If rport is 0, the TCP port will be allocated on the remote.
      Parameters:
      bind_address - bind address
      rport - remote port
      host - host address
      lport - local port
      sf - socket factory
      Throws:
      JSchException
    • setPortForwardingR

      public void setPortForwardingR​(int rport, java.lang.String daemon) throws JSchException
      Registers the remote port forwarding for the loopback interface of the remote. The TCP connection to rport on the remote will be forwarded to an instance of the class daemon. The class specified by daemon must implement ForwardedTCPIPDaemon.
      Parameters:
      rport - remote port
      daemon - class name, which implements "ForwardedTCPIPDaemon"
      Throws:
      JSchException
      See Also:
      setPortForwardingR(String bind_address, int rport, String daemon, Object[] arg)
    • setPortForwardingR

      public void setPortForwardingR​(int rport, java.lang.String daemon, java.lang.Object[] arg) throws JSchException
      Registers the remote port forwarding for the loopback interface of the remote. The TCP connection to rport on the remote will be forwarded to an instance of the class daemon with the argument arg. The class specified by daemon must implement ForwardedTCPIPDaemon.
      Parameters:
      rport - remote port
      daemon - class name, which implements "ForwardedTCPIPDaemon"
      arg - arguments for "daemon"
      Throws:
      JSchException
      See Also:
      setPortForwardingR(String bind_address, int rport, String daemon, Object[] arg)
    • setPortForwardingR

      public void setPortForwardingR​(java.lang.String bind_address, int rport, java.lang.String daemon, java.lang.Object[] arg) throws JSchException
      Registers the remote port forwarding. If bind_address is an empty string or "*", the port should be available from all interfaces. If bind_address is "localhost" or is not given, the listening port will be bound for local use only. Note that if GatewayPorts is "no" on the remote, "localhost" is always used as a bind_address. The TCP connection to rport on the remote will be forwarded to an instance of the class daemon with the argument arg. The class specified by daemon must implement ForwardedTCPIPDaemon.
      Parameters:
      bind_address - bind address
      rport - remote port
      daemon - class name, which implements "ForwardedTCPIPDaemon"
      arg - arguments for "daemon"
      Throws:
      JSchException
      See Also:
      setPortForwardingR(String bind_address, int rport, String daemon, Object[] arg)
    • getPortForwardingR

      public java.lang.String[] getPortForwardingR() throws JSchException
      Lists the registered remote port forwarding.
      Returns:
      a list of "rport:host:hostport"
      Throws:
      JSchException
    • setPortForwardingL

      public int setPortForwardingL​(java.lang.String conf) throws JSchException
      Registers the local port forwarding. The argument should be in the format like "[bind_address:]port:host:hostport". If bind_address is an empty string or "*", the port should be available from all interfaces. If bind_address is "localhost" or is not given, the listening port will be bound for local use only.
      Parameters:
      conf - configuration of local port forwarding
      Returns:
      an assigned port number
      Throws:
      JSchException
      See Also:
      setPortForwardingL(String bind_address, int lport, String host, int rport)
    • setPortForwardingR

      public int setPortForwardingR​(java.lang.String conf) throws JSchException
      Registers the remote port forwarding. The argument should be in the format like "[bind_address:]port:host:hostport". If the bind_address is not given, the default is to only bind to loopback addresses. If the bind_address is "*" or an empty string, then the forwarding is requested to listen on all interfaces. Note that if GatewayPorts is "no" on the remote, "localhost" is always used for bind_address. If the specified remote is "0", the TCP port will be allocated on the remote.
      Parameters:
      conf - configuration of remote port forwarding
      Returns:
      an allocated TCP port on the remote.
      Throws:
      JSchException
      See Also:
      setPortForwardingR(String bind_address, int rport, String host, int rport)
    • getStreamForwarder

      public Channel getStreamForwarder​(java.lang.String host, int port) throws JSchException
      Instantiates an instance of stream-forwarder to host:port. Set I/O stream to the given channel, and then invoke Channel#connect() method.
      Parameters:
      host - remote host, which the given stream will be plugged to.
      port - remote port, which the given stream will be plugged to.
      Throws:
      JSchException
    • delPortForwardingR

      public void delPortForwardingR​(int rport) throws JSchException
      Cancels the remote port forwarding assigned at remote TCP port rport.
      Parameters:
      rport - remote TCP port
      Throws:
      JSchException
    • delPortForwardingR

      public void delPortForwardingR​(java.lang.String bind_address, int rport) throws JSchException
      Cancels the remote port forwarding assigned at remote TCP port rport bound on the interface at bind_address.
      Parameters:
      bind_address - bind address of the interface on the remote
      rport - remote TCP port
      Throws:
      JSchException
    • setProxy

      public void setProxy​(Proxy proxy)
    • setHost

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

      public void setPort​(int port)
    • setUserInfo

      public void setUserInfo​(UserInfo userinfo)
    • getUserInfo

      public UserInfo getUserInfo()
    • setInputStream

      public void setInputStream​(java.io.InputStream in)
    • setOutputStream

      public void setOutputStream​(java.io.OutputStream out)
    • setX11Host

      public void setX11Host​(java.lang.String host)
    • setX11Port

      public void setX11Port​(int port)
    • setX11Cookie

      public void setX11Cookie​(java.lang.String cookie)
    • setPassword

      public void setPassword​(java.lang.String password)
    • setPassword

      public void setPassword​(byte[] password)
    • setConfig

      public void setConfig​(java.util.Properties newconf)
    • setConfig

      public void setConfig​(java.util.Hashtable<java.lang.String,​java.lang.String> newconf)
    • setConfig

      public void setConfig​(java.lang.String key, java.lang.String value)
    • getConfig

      public java.lang.String getConfig​(java.lang.String key)
    • setSocketFactory

      public void setSocketFactory​(SocketFactory sfactory)
    • isConnected

      public boolean isConnected()
    • getTimeout

      public int getTimeout()
    • setTimeout

      public void setTimeout​(int timeout) throws JSchException
      Throws:
      JSchException
    • getServerVersion

      public java.lang.String getServerVersion()
    • getClientVersion

      public java.lang.String getClientVersion()
    • setClientVersion

      public void setClientVersion​(java.lang.String cv)
    • sendIgnore

      public void sendIgnore() throws java.lang.Exception
      Throws:
      java.lang.Exception
    • sendKeepAliveMsg

      public void sendKeepAliveMsg() throws java.lang.Exception
      Throws:
      java.lang.Exception
    • noMoreSessionChannels

      public void noMoreSessionChannels() throws java.lang.Exception
      Throws:
      java.lang.Exception
    • getHostKey

      public HostKey getHostKey()
    • getHost

      public java.lang.String getHost()
    • getUserName

      public java.lang.String getUserName()
    • getPort

      public int getPort()
    • setHostKeyAlias

      public void setHostKeyAlias​(java.lang.String hostKeyAlias)
    • getHostKeyAlias

      public java.lang.String getHostKeyAlias()
    • setServerAliveInterval

      public void setServerAliveInterval​(int interval) throws JSchException
      Sets the interval to send a keep-alive message. If zero is specified, any keep-alive message must not be sent. The default interval is zero.
      Parameters:
      interval - the specified interval, in milliseconds.
      Throws:
      JSchException
      See Also:
      getServerAliveInterval()
    • getServerAliveInterval

      public int getServerAliveInterval()
      Returns setting for the interval to send a keep-alive message.
      See Also:
      setServerAliveInterval(int)
    • setServerAliveCountMax

      public void setServerAliveCountMax​(int count)
      Sets the number of keep-alive messages which may be sent without receiving any messages back from the server. If this threshold is reached while keep-alive messages are being sent, the connection will be disconnected. The default value is one.
      Parameters:
      count - the specified count
      See Also:
      getServerAliveCountMax()
    • getServerAliveCountMax

      public int getServerAliveCountMax()
      Returns setting for the threshold to send keep-alive messages.
      See Also:
      setServerAliveCountMax(int)
    • setDaemonThread

      public void setDaemonThread​(boolean enable)
    • setIdentityRepository

      public void setIdentityRepository​(IdentityRepository identityRepository)
      Sets the identityRepository, which will be referred in the public key authentication. The default value is null.
      Parameters:
      identityRepository -
      See Also:
      getIdentityRepository()
    • setHostKeyRepository

      public void setHostKeyRepository​(HostKeyRepository hostkeyRepository)
      Sets the hostkeyRepository, which will be referred in checking host keys.
      Parameters:
      hostkeyRepository -
      See Also:
      getHostKeyRepository()
    • getHostKeyRepository

      public HostKeyRepository getHostKeyRepository()
      Gets the hostkeyRepository. If this.hostkeyRepository is null, JSch#getHostKeyRepository() will be invoked.
      See Also:
      JSch.getHostKeyRepository()