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.

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>

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.

leaveOpen bool

Whether to leave stream open when the client is disposed.

cancellationToken CancellationToken

Cancels the connection attempt.

Returns

Task<SshClient>