Table of Contents

Constructor SftpFileProvider

Namespace
SshSharp.FileProviders
Assembly
SshSharp.FileProviders.dll

SftpFileProvider(SftpClient, string, SftpFileProviderOptions?)

Serves the files under root on the server.

public SftpFileProvider(SftpClient sftp, string root, SftpFileProviderOptions? options = null)

Parameters

sftp SftpClient

The SFTP session to use; it stays the caller's to dispose, after the provider is no longer used.

root string

The directory on the server, absolute or relative to the login directory (. for the login directory itself).

options SftpFileProviderOptions

Caching and timeouts.

SftpFileProvider(Func<CancellationToken, Task<SftpClient>>, string, SftpFileProviderOptions?)

Serves the files under root on the server, through sessions from sessionFactory: one is opened on the first lookup and shared by every lookup after it, and a new one is opened when the session or its connection fails. The provider owns the sessions it opens and disposes them (dispose the provider when it is no longer used).

public SftpFileProvider(Func<CancellationToken, Task<SftpClient>> sessionFactory, string root, SftpFileProviderOptions? options = null)

Parameters

sessionFactory Func<CancellationToken, Task<SftpClient>>

Opens a new SFTP session; called on the first lookup and after a failure, never concurrently.

root string

The directory on the server, absolute or relative to the login directory (. for the login directory itself).

options SftpFileProviderOptions

Caching and timeouts.

Remarks

Only a session that has ended is replaced (IsConnected false: the connection dropped, a keep-alive declared it dead, and so on), and one found ended before a lookup is replaced before that lookup uses it; a missing or unreadable file, or one request's timeout, is not a failure of the session. Lookups that find no session share one call to the factory, so a dropped connection is followed by one reconnect, not one per request; a lookup that fails because the connection dropped is tried once more on a new session. If the factory fails, the lookup fails with an SshException and the next one calls the factory again. Opening a session counts against OperationTimeout.

The factory opens a session on a connection it manages: the provider disposes the SftpClient, never the connection under it. With the dependency injection package, ct => connections.OpenSftpAsync("name", ct) opens it on the shared connection, which is itself opened again when it drops. Streams already open on a failed session fail; open them again.