Skip to content

SFTP Storage

Robin Rodricks edited this page Jul 23, 2026 · 13 revisions

To use this, you need to reference FluentStorage.SFTP package first, which wraps SSH.NET.

The provider respects folder structure of the remote SFTP share.

Connect to SFTP Server

You can instantiate it either by using a simple helper method accepting the most basic parameters, like hostname, port, username and password, however for custom scenarios you can always construct your own instance of SftpClient from the SSH.NET library and pass it to FluentStorage to manage:

IStore store = SftpStorage.FromCredentials("myhost.com", "username", "password");

// With a custom port and a private key file
IStore store = SftpStorage.FromPrivateKey("myhost.com", 2222, "username", new PrivateKeyFile("filename"));

// With both password and public-key authentication as an example, real world scenarios may need extra customisations
var connectionInfo = new ConnectionInfo("sftp.foo.com", "guest", new PasswordAuthenticationMethod("guest", "pwd"), new PrivateKeyAuthenticationMethod("rsa.key"));
IStore store = SftpStorage.FromConnectionInfo(connectionInfo);

Connect using Connection Strings

To create from connection string, first register the module when your program starts by calling StorageFactory.Modules.UseSftpStorage(); then use the following connections tring:

IStore store = StorageFactory.FromConnectionString("sftp://host=hostname;user=username;password=password");

Perform storage operations

Use our simple polycloud API to perform file and object manipulation operations.

Path handling

SFTP uses unified paths, however all file paths provided in API calls are appended to the "root directory" set when creating the SFTP store.

Special handling

SFTP has special handling for:

  • GetServer - Returns all possible SFTP server metadata
  • GetObjectChecksum - Fast implementation which computes a server-side checksum of the file using native SSH Shell commands.
    • It uses a powerful engine built for Windows and Unix support, it detects which Shell utilities are available once, then quickly uses this information to compute a server-side hash of the file without needing to download it.
    • Since it is running SSH Shell commands, it responsibly performs many security checks on the given file path to prevent path-injection and command-injection using the tried-and-tested Security engine from FluentFTP.
  • ListDirectory - Correctly lists files based on the given filters, and skips junk file entries
  • ListObjects - Correctly lists files, and skips junk file entries
  • UploadObject, SetBytes, SetObject - Automatically creates the parent directory structure before writing the file. Uses the fastest available SFTP API to transfer file data quickly.
  • DownloadObject, GetBytes, GetObject - Uses the fastest available SFTP API to transfer file data quickly.
  • CreateDirectory - Creates the entire directory path instead of just the last folder part

Clone this wiki locally