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
connectionsISshConnectionProviderThe shared connections.
namestringThe endpoint, as registered with
AddSshClient.cancellationTokenCancellationTokenCancels connecting and opening the session.
Returns
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
endpointISshEndpointThe endpoint, resolved as a keyed service.
cancellationTokenCancellationTokenCancels connecting and opening the session.
Returns
Exceptions
- OptionsValidationException
The endpoint's settings are invalid.
- SshException
The connection failed, or the server offers no SFTP.
- TimeoutException
Connecting took longer than ConnectTimeout.