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. 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
hoststringportintoptionsSshClientOptionscancellationTokenCancellationToken
Returns
Exceptions
- SshException
The server could not be reached (ConnectFailed), the attempt took longer than ConnectTimeout (Timeout), or the handshake or authentication failed.
- OperationCanceledException
cancellationTokenwas 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
streamStreamA connected, duplex stream.
optionsSshClientOptionsConnection options. ConnectTimeout bounds the handshake and authentication.
leaveOpenboolWhether to leave
streamopen when the client is disposed.cancellationTokenCancellationTokenCancels the connection attempt.