Interface ClientSession

    • Field Detail

      • REMOTE_COMMAND_WAIT_EVENTS

        static final java.util.Set<ClientChannelEvent> REMOTE_COMMAND_WAIT_EVENTS
    • Method Detail

      • getConnectAddress

        java.net.SocketAddress getConnectAddress()
        Returns the original address (after having been translated through host configuration entries if any) that was request to connect. It contains the original host or address string that was used. Note: this may be different than the result of the Session.getIoSession() report of the remote peer
        Returns:
        The original requested address
      • getConnectionContext

        AttributeRepository getConnectionContext()
        Returns:
        The "context" data provided when session connection was established - null if none.
      • getServerKey

        java.security.PublicKey getServerKey()
        Retrieves the server's key
        Returns:
        The server's PublicKey - null if KEX not started or not completed
      • createChannel

        ClientChannel createChannel​(java.lang.String type)
                             throws java.io.IOException
        Create a channel of the given type. Same as calling createChannel(type, null).
        Parameters:
        type - The channel type
        Returns:
        The created ClientChannel
        Throws:
        java.io.IOException - If failed to create the requested channel
      • createChannel

        ClientChannel createChannel​(java.lang.String type,
                                    java.lang.String subType)
                             throws java.io.IOException
        Create a channel of the given type and sub-type.
        Parameters:
        type - The channel type
        subType - The channel sub-type
        Returns:
        The created ClientChannel
        Throws:
        java.io.IOException - If failed to create the requested channel
      • createShellChannel

        default ChannelShell createShellChannel()
                                         throws java.io.IOException
        Create a channel to start a shell using default PTY settings and environment.
        Returns:
        The created ChannelShell
        Throws:
        java.io.IOException - If failed to create the requested channel
      • createShellChannel

        ChannelShell createShellChannel​(PtyChannelConfigurationHolder ptyConfig,
                                        java.util.Map<java.lang.String,​?> env)
                                 throws java.io.IOException
        Create a channel to start a shell using specific PTY settings and/or environment.
        Parameters:
        ptyConfig - The PTY configuration to use - if null then internal defaults are used
        env - Extra environment configuration to be transmitted to the server - ignored if null/empty.
        Returns:
        The created ChannelShell
        Throws:
        java.io.IOException - If failed to create the requested channel
      • createExecChannel

        default ChannelExec createExecChannel​(java.lang.String command)
                                       throws java.io.IOException
        Create a channel to execute a command using default PTY settings and environment.
        Parameters:
        command - The command to execute
        Returns:
        The created ChannelExec
        Throws:
        java.io.IOException - If failed to create the requested channel
      • createExecChannel

        default ChannelExec createExecChannel​(java.lang.String command,
                                              PtyChannelConfigurationHolder ptyConfig,
                                              java.util.Map<java.lang.String,​?> env)
                                       throws java.io.IOException
        Create a channel to execute a command using specific PTY settings and/or environment.
        Parameters:
        command - The command to execute
        ptyConfig - The PTY configuration to use - if null then internal defaults are used
        env - Extra environment configuration to be transmitted to the server - ignored if null/empty.
        Returns:
        The created ChannelExec
        Throws:
        java.io.IOException - If failed to create the requested channel
      • createExecChannel

        ChannelExec createExecChannel​(java.lang.String command,
                                      java.nio.charset.Charset charset,
                                      PtyChannelConfigurationHolder ptyConfig,
                                      java.util.Map<java.lang.String,​?> env)
                               throws java.io.IOException
        Create a channel to execute a command using specific PTY settings and/or environment.
        Parameters:
        command - The command to execute
        charset - The Charset to use for sending the command string
        ptyConfig - The PTY configuration to use - if null then internal defaults are used
        env - Extra environment configuration to be transmitted to the server - ignored if null/empty.
        Returns:
        The created ChannelExec
        Throws:
        java.io.IOException - If failed to create the requested channel
      • createExecChannel

        ChannelExec createExecChannel​(byte[] command,
                                      PtyChannelConfigurationHolder ptyConfig,
                                      java.util.Map<java.lang.String,​?> env)
                               throws java.io.IOException
        Create a channel to execute a command using specific PTY settings and/or environment.
        Parameters:
        command - The command to execute
        ptyConfig - The PTY configuration to use - if null then internal defaults are used
        env - Extra environment configuration to be transmitted to the server - ignored if null/empty.
        Returns:
        The created ChannelExec
        Throws:
        java.io.IOException - If failed to create the requested channel
      • executeRemoteCommand

        default java.lang.String executeRemoteCommand​(java.lang.String command)
                                               throws java.io.IOException
        Execute a command that requires no input and returns its output
        Parameters:
        command - The command to execute
        Returns:
        The command's standard output result (assumed to be in US-ASCII)
        Throws:
        java.io.IOException - If failed to execute the command - including if anything was written to the standard error or a non-zero exit status was received. If this happens, then a RemoteException is thrown with a cause of ServerException containing the remote captured standard error - including CR/LF(s)
        See Also:
        executeRemoteCommand(String, OutputStream, Charset)
      • executeRemoteCommand

        default java.lang.String executeRemoteCommand​(java.lang.String command,
                                                      java.io.OutputStream stderr,
                                                      java.nio.charset.Charset charset)
                                               throws java.io.IOException
        Execute a command that requires no input and returns its output
        Parameters:
        command - The command to execute - without a terminating LF
        stderr - Standard error output stream - if null then error stream data is ignored. Note: if the stream is not null then it will be left open when this method returns or exception is thrown
        charset - The command Charset for input/output/error - if null then US_ASCII is assumed
        Returns:
        The command's standard output result
        Throws:
        java.io.IOException - If failed to manage the command channel - Note: the code does not check if anything was output to the standard error stream, but does check the reported exit status (if any) for non-zero value. If non-zero exit status received then a RemoteException is thrown with' a ServerException cause containing the exits value
        See Also:
        executeRemoteCommand(String, OutputStream, OutputStream, Charset)
      • executeRemoteCommand

        default void executeRemoteCommand​(java.lang.String command,
                                          java.io.OutputStream stdout,
                                          java.io.OutputStream stderr,
                                          java.nio.charset.Charset charset)
                                   throws java.io.IOException
        Execute a command that requires no input and redirects its STDOUT/STDERR streams to the user-provided ones
        Parameters:
        command - The command to execute - without a terminating LF
        stdout - Standard output stream - if null then stream data is ignored. Note: if the stream is not null then it will be left open when this method returns or exception is thrown
        stderr - Error output stream - if null then stream data is ignored. Note: if the stream is not null then it will be left open when this method returns or exception is thrown
        charset - The command Charset for output/error - if null then US_ASCII is assumed
        Throws:
        java.io.IOException - If failed to execute the command or got a non-zero exit status
        See Also:
        validateCommandExitStatusCode
      • createSubsystemChannel

        ChannelSubsystem createSubsystemChannel​(java.lang.String subsystem)
                                         throws java.io.IOException
        Create a subsystem channel.
        Parameters:
        subsystem - The subsystem name
        Returns:
        The created ChannelSubsystem
        Throws:
        java.io.IOException - If failed to create the requested channel
      • createDirectTcpipChannel

        ChannelDirectTcpip createDirectTcpipChannel​(SshdSocketAddress local,
                                                    SshdSocketAddress remote)
                                             throws java.io.IOException
        Create a direct tcp-ip channel which can be used to stream data to a remote port from the server.
        Parameters:
        local - The local address
        remote - The remote address
        Returns:
        The created ChannelDirectTcpip
        Throws:
        java.io.IOException - If failed to create the requested channel
      • createLocalPortForwardingTracker

        default ExplicitPortForwardingTracker createLocalPortForwardingTracker​(int localPort,
                                                                               SshdSocketAddress remote)
                                                                        throws java.io.IOException
        Starts a local port forwarding and returns a tracker that stops the forwarding when the close() method is called. This tracker can be used in a try-with-resource block to ensure cleanup of the set up forwarding.
        Parameters:
        localPort - The local port - if zero one is allocated
        remote - The remote address
        Returns:
        The tracker instance
        Throws:
        java.io.IOException - If failed to set up the requested forwarding
        See Also:
        PortForwardingManager.startLocalPortForwarding(SshdSocketAddress, SshdSocketAddress)
      • createDynamicPortForwardingTracker

        default DynamicPortForwardingTracker createDynamicPortForwardingTracker​(SshdSocketAddress local)
                                                                         throws java.io.IOException
        Starts a dynamic port forwarding and returns a tracker that stops the forwarding when the close() method is called. This tracker can be used in a try-with-resource block to ensure cleanup of the set up forwarding.
        Parameters:
        local - The local address
        Returns:
        The tracker instance
        Throws:
        java.io.IOException - If failed to set up the requested forwarding
        See Also:
        PortForwardingManager.startDynamicPortForwarding(SshdSocketAddress)
      • getMetadataMap

        java.util.Map<java.lang.Object,​java.lang.Object> getMetadataMap()
        Access to the metadata.
        Returns:
        The metadata Map - Note: access to the map is not synchronized in any way - up to the user to take care of mutual exclusion if necessary
      • switchToNoneCipher

        KeyExchangeFuture switchToNoneCipher()
                                      throws java.io.IOException

        Switch to a none cipher for performance.

        This should be done after the authentication phase has been performed. After such a switch, interactive channels are not allowed anymore. Both client and server must have been configured to support the none cipher. If that's not the case, the returned future will be set with an exception.

        Returns:
        an KeyExchangeFuture that can be used to wait for the exchange to be finished
        Throws:
        java.io.IOException - if a key exchange is already running
      • passwordIteratorOf

        static java.util.Iterator<java.lang.String> passwordIteratorOf​(ClientSession session)
                                                                throws java.io.IOException,
                                                                       java.security.GeneralSecurityException
        Creates a "unified" Iterator of passwords out of the registered passwords and the extra available ones as a single iterator of passwords
        Parameters:
        session - The ClientSession - ignored if null (i.e., empty iterator returned)
        Returns:
        The wrapping iterator
        Throws:
        java.io.IOException - If failed to load the passwords
        java.security.GeneralSecurityException - If some security issue with the passwords
        See Also:
        ClientAuthenticationManager.getRegisteredIdentities(), ClientAuthenticationManager.getPasswordIdentityProvider()