Table of Contents

Method OpenSftpAsync

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

OpenSftpAsync(ISshConnectionProvider, string, CancellationToken)

Opens a new SFTP session on the shared connection to the endpoint name, connecting first if it is down. The caller owns the session and disposes it; the connection stays the provider's. As the session factory of SftpFileProvider or SftpFileSystem, it lets the adapter follow the shared connection: after a drop, the adapter's next session is opened on the new connection.

public static Task<SftpClient> OpenSftpAsync(this ISshConnectionProvider connections, string name, CancellationToken cancellationToken = default)

Parameters

connections ISshConnectionProvider

The shared connections.

name string

The endpoint, as registered with AddSshClient.

cancellationToken CancellationToken

Cancels connecting and opening the session.

Returns

Task<SftpClient>

Remarks

When the shared connection turns out to have dropped as the session opens, the provider connects again and the session is opened on the new connection, once.

Exceptions

InvalidOperationException

No endpoint is registered as name.

OptionsValidationException

The endpoint's settings are invalid.

SshException

The connection failed (see GetClientAsync(string, CancellationToken)), or the server offers no SFTP.

TimeoutException

Connecting took longer than ConnectTimeout.

OpenSftpAsync(ISshEndpoint, CancellationToken)

Opens a new SFTP session on the endpoint's shared connection, as OpenSftpAsync(ISshConnectionProvider, string, CancellationToken) does for its name.

public static Task<SftpClient> OpenSftpAsync(this ISshEndpoint endpoint, CancellationToken cancellationToken = default)

Parameters

endpoint ISshEndpoint

The endpoint, resolved as a keyed service.

cancellationToken CancellationToken

Cancels connecting and opening the session.

Returns

Task<SftpClient>

Exceptions

OptionsValidationException

The endpoint's settings are invalid.

SshException

The connection failed, or the server offers no SFTP.

TimeoutException

Connecting took longer than ConnectTimeout.