Constructor SftpFileSystem
- Namespace
- SshSharp.IO.Abstractions
- Assembly
- SshSharp.IO.Abstractions.dll
SftpFileSystem(SftpClient, SftpFileSystemOptions?)
A file system over sftp.
public SftpFileSystem(SftpClient sftp, SftpFileSystemOptions? options = null)
Parameters
sftpSftpClientThe SFTP session to use; it stays the caller's to dispose, after the file system is no longer used.
optionsSftpFileSystemOptionsTimeouts.
SftpFileSystem(Func<CancellationToken, Task<SftpClient>>, SftpFileSystemOptions?)
A file system over sessions from sessionFactory: one is opened on the first call and shared by every call
after it, and a new one is opened when the session or its connection fails. The file system owns the sessions it opens and
disposes them (dispose the file system when it is no longer used).
public SftpFileSystem(Func<CancellationToken, Task<SftpClient>> sessionFactory, SftpFileSystemOptions? options = null)
Parameters
sessionFactoryFunc<CancellationToken, Task<SftpClient>>Opens a new SFTP session; called on first use and after a failure, never concurrently.
optionsSftpFileSystemOptionsTimeouts.
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 call is replaced before that call uses it; an SFTP error (a missing file, a denied request) or one request's timeout is not a failure of the session. Calls that find no session share one call to the factory, so a dropped connection is followed by one reconnect, not one per caller. The call that meets the dropped connection fails with an IOException, unless it only reads (an attribute lookup, a listing, a whole-file read, opening a file to read): those are tried once more on a new session. A call that writes is not, since the server may have done it before the connection dropped. If the factory fails, the call fails with an IOException 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 file system 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.