Class JschSession

  • All Implemented Interfaces:
    RemoteSession, RemoteSession2

    public class JschSession
    extends java.lang.Object
    implements RemoteSession2
    Run remote commands using Jsch.

    This class is the default session implementation using Jsch. Note that JschConfigSessionFactory is used to create the actual session passed to the constructor.

    Since:
    6.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) com.jcraft.jsch.Session sock  
      (package private) URIish uri  
    • Constructor Summary

      Constructors 
      Constructor Description
      JschSession​(com.jcraft.jsch.Session session, URIish uri)
      Create a new session object by passing the real Jsch session and the URI information.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void disconnect()
      Disconnects the remote session.
      java.lang.Process exec​(java.lang.String command, int timeout)
      Creates a new remote Process to execute the given command.
      java.lang.Process exec​(java.lang.String command, java.util.Map<java.lang.String,​java.lang.String> environment, int timeout)
      Creates a new remote Process to execute the given command.
      FtpChannel getFtpChannel()
      Obtains an FtpChannel for performing FTP operations over this RemoteSession.
      com.jcraft.jsch.Channel getSftpChannel()
      Deprecated.
      since 5.2; use getFtpChannel() instead
      • Methods inherited from class java.lang.Object

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

      • sock

        final com.jcraft.jsch.Session sock
    • Constructor Detail

      • JschSession

        public JschSession​(com.jcraft.jsch.Session session,
                           URIish uri)
        Create a new session object by passing the real Jsch session and the URI information.
        Parameters:
        session - the real Jsch session created elsewhere.
        uri - the URI information for the remote connection
    • Method Detail

      • exec

        public java.lang.Process exec​(java.lang.String command,
                                      int timeout)
                               throws java.io.IOException
        Creates a new remote Process to execute the given command. The returned process's streams exist and are connected, and execution of the process is already started.
        Specified by:
        exec in interface RemoteSession
        Parameters:
        command - command to execute
        timeout - timeout value, in seconds, for creating the remote process
        Returns:
        a new remote process, already started
        Throws:
        java.io.IOException - may be thrown in several cases. For example, on problems opening input or output streams or on problems connecting or communicating with the remote host. For the latter two cases, a TransportException may be thrown (a subclass of java.io.IOException).
      • exec

        public java.lang.Process exec​(java.lang.String command,
                                      java.util.Map<java.lang.String,​java.lang.String> environment,
                                      int timeout)
                               throws java.io.IOException
        Creates a new remote Process to execute the given command. The returned process's streams exist and are connected, and execution of the process is already started.
        Specified by:
        exec in interface RemoteSession2
        Parameters:
        command - command to execute
        environment - environment variables to pass on
        timeout - timeout value, in seconds, for creating the remote process
        Returns:
        a new remote process, already started
        Throws:
        java.io.IOException - may be thrown in several cases. For example, on problems opening input or output streams or on problems connecting or communicating with the remote host. For the latter two cases, a TransportException may be thrown (a subclass of java.io.IOException).
      • disconnect

        public void disconnect()
        Disconnects the remote session.
        Specified by:
        disconnect in interface RemoteSession
      • getSftpChannel

        @Deprecated
        public com.jcraft.jsch.Channel getSftpChannel()
                                               throws com.jcraft.jsch.JSchException
        Deprecated.
        since 5.2; use getFtpChannel() instead
        A kludge to allow TransportSftp to get an Sftp channel from Jsch. Ideally, this method would be generic, which would require implementing generic Sftp channel operations in the RemoteSession class.
        Returns:
        a channel suitable for Sftp operations.
        Throws:
        com.jcraft.jsch.JSchException - on problems getting the channel.