Table of Contents

Method ConnectAsync

Namespace
SshSharp
Assembly
SshSharp.dll

ConnectAsync(string, SshConfigConnectOptions?, CancellationToken)

Connects like ssh destination does: destination ([user@]host, an alias, or ssh://[user@]host[:port]) is resolved with ssh_config, and the connection follows it: HostName, Port, User, IdentityFile keys, known_hosts with StrictHostKeyChecking, Ciphers/KexAlgorithms/HostKeyAlgorithms/MACs, ProxyJump chains, ProxyCommand, ServerAliveInterval/ServerAliveCountMax, ConnectTimeout and AddressFamily.

public static Task<SshClient> ConnectAsync(string destination, SshConfigConnectOptions? options = null, CancellationToken cancellationToken = default)

Parameters

destination string
options SshConfigConnectOptions
cancellationToken CancellationToken

Returns

Task<SshClient>

Exceptions

SshHostKeyException

The host key is not trusted under the configured policy.

SshAuthenticationException

No configured key or password was accepted.

ConnectAsync(string, int, SshClientOptions, CancellationToken)

Connects to host over TCP, performs the handshake and authenticates. ConnectTimeout bounds the whole attempt, and AddressFamily chooses which of the host's addresses are tried. With JumpHosts, the server is reached through them, and host is resolved by the last one.

public static Task<SshClient> ConnectAsync(string host, int port, SshClientOptions options, CancellationToken cancellationToken = default)

Parameters

host string
port int
options SshClientOptions
cancellationToken CancellationToken

Returns

Task<SshClient>

Exceptions

SshException

The server could not be reached (ConnectFailed), the attempt took longer than ConnectTimeout (Timeout), or the handshake or authentication failed.

OperationCanceledException

cancellationToken was cancelled.

ConnectAsync(Stream, SshClientOptions, bool, CancellationToken)

Runs the SSH protocol over an existing stream (a socket, a WebSocket wrapper, a tunnel from another connection, ...).

public static Task<SshClient> ConnectAsync(Stream stream, SshClientOptions options, bool leaveOpen = false, CancellationToken cancellationToken = default)

Parameters

stream Stream

A connected, duplex stream.

options SshClientOptions

Connection options. ConnectTimeout bounds the handshake and authentication.

leaveOpen bool

Whether to leave stream open when the client is disposed.

cancellationToken CancellationToken

Cancels the connection attempt.

Returns

Task<SshClient>