Table of Contents

Class SftpFileProvider

Namespace
SshSharp.FileProviders
Assembly
SshSharp.FileProviders.dll

An IFileProvider over SFTP: the files under a directory on an SSH server, for ASP.NET Core static files, Razor views, configuration and anything else that reads through Microsoft.Extensions.FileProviders. Read-only; nothing is mounted, so only this application sees the files.

public sealed class SftpFileProvider : IFileProvider
Inheritance
SftpFileProvider
Implements
Inherited Members

Remarks

IFileProvider is synchronous, so each lookup waits for an SFTP round trip; attributes and listings are cached for CacheDuration to keep that cheap. Streams from CreateReadStream() read ahead, and are fastest read asynchronously (as ASP.NET Core's static files middleware does).

Paths cannot leave Root: any .. segment gives a file that does not exist. Symbolic links are followed (on the server, which decides where they lead). Watch(string) never signals: SFTP has no change notifications.

Constructors

SftpFileProvider(SftpClient, string, SftpFileProviderOptions?)

Serves the files under root on the server.

Properties

Root

The directory on the server that the provider serves.

Methods

ClearCache()

Forgets the cached attributes and listings, so the next lookups ask the server.

GetDirectoryContents(string)

The entries of the directory at subpath, or contents with Exists false.

GetFileInfo(string)

The file at subpath, or one with Exists false.

Watch(string)

A token that never changes: SFTP cannot tell when a file changes.