Feature: SFTP Provider (ManagedCode.Storage.Sftp)
Purpose
Implement IStorage on top of SFTP using SSH (for legacy systems and air-gapped environments).
Main Flows
flowchart LR
App --> S[SftpStorage : ISftpStorage]
S --> SSH[SSH.NET]
SSH --> Server[(SFTP Server)]
Components
Storages/ManagedCode.Storage.Sftp/SftpStorage.csStorages/ManagedCode.Storage.Sftp/SftpStorageProvider.cs- DI:
- Options:
DI Wiring
dotnet add package ManagedCode.Storage.Sftp
using ManagedCode.Storage.Sftp.Extensions;
builder.Services.AddSftpStorageAsDefault(options =>
{
options.Host = "sftp.example.com";
options.Username = configuration["Sftp:Username"];
options.Password = configuration["Sftp:Password"];
options.RemoteDirectory = "/uploads";
});
Current Behavior
- Supports password and key-based auth (
PrivateKeyPath/PrivateKeyContent). AcceptAnyHostKeyexists for dev/test only; production should useHostKeyFingerprint.- Can create directories automatically (
CreateDirectoryIfNotExists).
Tests
Tests/ManagedCode.Storage.Tests/Storages/Sftp/SftpUploadTests.csTests/ManagedCode.Storage.Tests/Storages/Sftp/SftpDownloadTests.csTests/ManagedCode.Storage.Tests/Storages/Sftp/SftpBlobTests.csTests/ManagedCode.Storage.Tests/Storages/Sftp/SftpStreamTests.csTests/ManagedCode.Storage.Tests/Storages/Sftp/SftpContainerTests.cs