SshSession

Represents an SSH session channel (RFC 4254 section 6).

Session channels are used for interactive shells, command execution, and subsystem invocation (like SFTP).

Inheritors

Properties

Link copied to clipboard
abstract val exitInfo: Deferred<SessionExit?>

Completes with how the remote process terminated once the server reports it (RFC 4254 section 6.10), or with null when the channel closes without an exit-status/exit-signal notification. Servers are not required to send one, so null means unknown, not failure.

Link copied to clipboard
abstract val isOpen: Boolean
Link copied to clipboard
abstract val localChannelNumber: Int
Link copied to clipboard
abstract val remoteChannelNumber: Int
Link copied to clipboard
abstract val stderr: ReceiveChannel<ByteArray>

Standard error, with the same drain and explicit-close contract as stdout.

Link copied to clipboard
abstract val stdout: ReceiveChannel<ByteArray>

Standard output. Data received before remote channel close remains readable through automatic connection teardown. Explicit session close or client disconnect discards it.

Functions

Link copied to clipboard
abstract override fun close()

Discard unread output and release delivery resources, including after remote close.

Link copied to clipboard
abstract suspend fun read(): ByteArray?
Link copied to clipboard
abstract suspend fun readExtended(): Pair<Int, ByteArray>?

Read non-stderr extended data. RFC 4254 data type 1 is exposed exclusively through stderr so the same remote bytes are not buffered twice.

Link copied to clipboard
abstract suspend fun requestEnv(name: String, value: String): Boolean

Request an environment variable for this session (RFC 4254 section 6.4). Call before requesting a shell, command, or subsystem. Servers may restrict names (OpenSSH uses AcceptEnv) and reject requests after process startup. Names and values are encoded as UTF-8. Returns false for NUL-containing input, a closed channel, or server rejection; rejection does not close the session.

Link copied to clipboard
abstract suspend fun requestExec(command: String): Boolean

Request execution of a command on this session channel (RFC 4254 section 6.5).

Link copied to clipboard
abstract suspend fun requestPty(terminalType: String = "xterm", widthChars: Int = 80, heightRows: Int = 24, widthPixels: Int = 0, heightPixels: Int = 0, terminalModes: ByteArray = byteArrayOf(0)): Boolean
Link copied to clipboard
abstract suspend fun requestShell(): Boolean
Link copied to clipboard
abstract suspend fun requestSubsystem(name: String): Boolean

Request a subsystem on this session channel (RFC 4254 section 6.5).

Link copied to clipboard
abstract suspend fun resizeTerminal(widthChars: Int, heightRows: Int, widthPixels: Int, heightPixels: Int): Boolean
Link copied to clipboard
abstract suspend fun sendEof()
Link copied to clipboard
abstract suspend fun write(data: ByteArray)

Write data, suspending for channel window credit and transport backpressure.