Table of Contents

Interface ISshConnectionProvider

Namespace
SshSharp.Extensions.DependencyInjection
Assembly
SshSharp.Extensions.DependencyInjection.dll

One long-lived connection per endpoint registered with services.AddSshClient(name), shared by its callers and opened again when it drops. The provider owns the clients and disposes them with the container: callers must not dispose them.

public interface ISshConnectionProvider
Extension Methods

Methods

GetClientAsync(string, CancellationToken)

The connected client for name: the shared one if it is still up, otherwise a new connection, which then becomes the shared one. Concurrent callers share one attempt. After a failed attempt the next one waits (from ReconnectDelay, doubling, up to MaxReconnectDelay); a call made during that wait fails at once, with an SshException whose inner exception is the last failure, rather than connecting again.

WatchAsync(string, CancellationToken)

The changes of the shared connection for name, as they happen, until cancellationToken is cancelled or the provider is disposed: Connected when it is opened, Disconnected when it ends, and Reconnected when a new connection replaces it. Use it to restore what lived on the old connection (forwardings, long-running commands) on the new one. Each enumeration is a watcher of its own; none misses an event, however slowly it reads.