Skip to content

SshTransportConnection

Defined in: src/protocols/ssh/transport/SshTransportConnection.ts:91

Live SSH transport connection over a TCP socket.

Runs the SSH identification exchange and key exchange handshake on the supplied socket, then provides an encrypted packet send/receive interface for higher-level SSH layers (authentication, connection, SFTP subsystem).

Usage:

const conn = new SshTransportConnection();
const result = await conn.connect(socket); // runs handshake
conn.sendPayload(payload); // post-NEWKEYS send
for await (const payload of conn.receivePayloads()) { ... }
conn.disconnect();
new SshTransportConnection(options?: SshTransportConnectionOptions): SshTransportConnection;

Defined in: src/protocols/ssh/transport/SshTransportConnection.ts:108

ParameterType
optionsSshTransportConnectionOptions

SshTransportConnection

connect(socket: Socket): Promise<SshTransportHandshakeResult>;

Defined in: src/protocols/ssh/transport/SshTransportConnection.ts:115

Runs the SSH handshake on a TCP-connected socket. Resolves when NEWKEYS completes and the transport is ready for encrypted messages. Rejects on socket error, abort, or protocol failure.

ParameterType
socketSocket

Promise<SshTransportHandshakeResult>


disconnect(reason?: SshDisconnectReason, description?: string): void;

Defined in: src/protocols/ssh/transport/SshTransportConnection.ts:336

Sends SSH_MSG_DISCONNECT and ends the socket. Safe to call multiple times; subsequent calls are no-ops.

ParameterTypeDefault value
reasonSshDisconnectReasonSshDisconnectReason.BY_APPLICATION
descriptionstring""

void


isConnected(): boolean;

Defined in: src/protocols/ssh/transport/SshTransportConnection.ts:363

boolean


receivePayloads(): AsyncGenerator<Buffer<ArrayBufferLike>>;

Defined in: src/protocols/ssh/transport/SshTransportConnection.ts:322

Async generator that yields inbound SSH payloads (post-NEWKEYS).

Transparent handling:

  • SSH_MSG_IGNORE (2) and SSH_MSG_DEBUG (4) are silently dropped.
  • SSH_MSG_DISCONNECT (1) from the server throws a ConnectionError.
  • Socket error or close terminates the generator.

AsyncGenerator<Buffer<ArrayBufferLike>>


sendPayload(payload: Buffer<ArrayBufferLike> | Uint8Array<ArrayBufferLike>): void;

Defined in: src/protocols/ssh/transport/SshTransportConnection.ts:306

Sends an SSH payload over the encrypted transport. The payload must start with the SSH message type byte.

ParameterType
payloadBuffer<ArrayBufferLike> | Uint8Array<ArrayBufferLike>

void