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
destinationstringoptionsSshConfigConnectOptionscancellationTokenCancellationToken
Returns
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
hoststringportintoptionsSshClientOptionscancellationTokenCancellationToken
Returns
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
streamStreamA connected, duplex stream.
optionsSshClientOptionsConnection options.
leaveOpenboolWhether to leave
streamopen when the client is disposed.cancellationTokenCancellationTokenCancels the connection attempt.