CommunityToolkit.Aspire.Sftp
13.4.1-beta.685
Prefix Reserved
dotnet add package CommunityToolkit.Aspire.Sftp --version 13.4.1-beta.685
NuGet\Install-Package CommunityToolkit.Aspire.Sftp -Version 13.4.1-beta.685
<PackageReference Include="CommunityToolkit.Aspire.Sftp" Version="13.4.1-beta.685" />
<PackageVersion Include="CommunityToolkit.Aspire.Sftp" Version="13.4.1-beta.685" />
<PackageReference Include="CommunityToolkit.Aspire.Sftp" />
paket add CommunityToolkit.Aspire.Sftp --version 13.4.1-beta.685
#r "nuget: CommunityToolkit.Aspire.Sftp, 13.4.1-beta.685"
#:package CommunityToolkit.Aspire.Sftp@13.4.1-beta.685
#addin nuget:?package=CommunityToolkit.Aspire.Sftp&version=13.4.1-beta.685&prerelease
#tool nuget:?package=CommunityToolkit.Aspire.Sftp&version=13.4.1-beta.685&prerelease
CommunityToolkit.Aspire.Sftp
Registers an SftpClient in the DI container for connecting to SFTP servers using SSH.NET.
Getting started
Prerequisites
- SFTP server.
Install the package
Install the Aspire SFTP Client library with NuGet:
dotnet add package CommunityToolkit.Aspire.Sftp
Usage example
In the Program.cs file of your project, call the AddSftpClient extension method to register an SftpClient for use via the dependency injection container. The method takes a connection name parameter.
builder.AddSftpClient("sftp");
Configuration
The Aspire SFTP Client integration provides multiple options to configure the server connection based on the requirements and conventions of your project.
Use a connection string
When using a connection string from the ConnectionStrings configuration section, you can provide the name of the connection string when calling builder.AddSftpClient():
builder.AddSftpClient("sftp");
And then the connection string will be retrieved from the ConnectionStrings configuration section:
{
"ConnectionStrings": {
"sftp": "sftp://localhost:22"
}
}
Use configuration providers
The Aspire SFTP Client integration supports Microsoft.Extensions.Configuration. It loads the SftpSettings from configuration by using the Aspire:Sftp:Client key. Example appsettings.json that configures some of the options:
{
"Aspire": {
"Sftp": {
"Client": {
"ConnectionString": "sftp://localhost:22",
"Username": "admin",
"Password": "password",
"DisableHealthChecks": false
}
}
}
}
Use inline delegates
Also you can pass the Action<SftpSettings> configureSettings delegate to set up some or all the options inline:
builder.AddSftpClient("sftp", settings =>
{
settings.Username = "admin";
settings.Password = "password";
});
Authentication options
The SFTP client supports two authentication methods:
- Password authentication: Provide
UsernameandPassword. - Private key authentication: Provide
UsernameandPrivateKeyFilepath.
{
"Aspire": {
"Sftp": {
"Client": {
"ConnectionString": "sftp://localhost:22",
"Username": "admin",
"PrivateKeyFile": "/path/to/private/key"
}
}
}
}
Keyed services
The integration also supports keyed services for multiple SFTP connections:
builder.AddKeyedSftpClient("sftp1");
builder.AddKeyedSftpClient("sftp2");
Then inject the keyed client:
public class MyService
{
private readonly SftpClient _client1;
private readonly SftpClient _client2;
public MyService(
[FromKeyedServices("sftp1")] SftpClient client1,
[FromKeyedServices("sftp2")] SftpClient client2)
{
_client1 = client1;
_client2 = client2;
}
}
AppHost extensions
In your AppHost project, install the CommunityToolkit.Aspire.Hosting.Sftp library with NuGet:
dotnet add package CommunityToolkit.Aspire.Hosting.Sftp
Then, in the Program.cs file of AppHost, register SFTP and consume the connection using the following methods:
var sftp = builder.AddSftp("sftp");
var myService = builder.AddProject<Projects.MyService>()
.WithReference(sftp);
The WithReference method configures a connection in the MyService project named sftp. In the Program.cs file of MyService, the SFTP connection can be consumed using:
builder.AddSftpClient("sftp");
Then, in your service, inject SftpClient and use it to interact with the SFTP server:
public class MyService
{
private readonly SftpClient _client;
public MyService(SftpClient client)
{
_client = client;
if (!_client.IsConnected)
{
_client.Connect();
}
}
public void UploadFile(string localPath, string remotePath)
{
using var fileStream = File.OpenRead(localPath);
_client.UploadFile(fileStream, remotePath);
}
public void DownloadFile(string remotePath, string localPath)
{
using var fileStream = File.Create(localPath);
_client.DownloadFile(remotePath, fileStream);
}
}
Additional documentation
- https://github.com/sshnet/SSH.NET
- https://learn.microsoft.com/dotnet/aspire/community-toolkit/hosting-sftp
Feedback & contributing
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- AspNetCore.HealthChecks.Network (>= 9.0.0)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.8)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.8)
- OpenTelemetry.Extensions.Hosting (>= 1.15.3)
- SSH.NET (>= 2025.1.0)
-
net8.0
- AspNetCore.HealthChecks.Network (>= 9.0.0)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.8)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.8)
- OpenTelemetry.Extensions.Hosting (>= 1.15.3)
- SSH.NET (>= 2025.1.0)
-
net9.0
- AspNetCore.HealthChecks.Network (>= 9.0.0)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.8)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.8)
- OpenTelemetry.Extensions.Hosting (>= 1.15.3)
- SSH.NET (>= 2025.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 13.4.1-beta.685 | 36 | 7/9/2026 |
| 13.4.1-beta.683 | 40 | 7/9/2026 |
| 13.4.1-beta.680 | 40 | 7/7/2026 |
| 13.4.1-beta.676 | 43 | 7/7/2026 |
| 13.4.1-beta.675 | 46 | 7/6/2026 |
| 13.4.1-beta.674 | 46 | 7/6/2026 |
| 13.4.0 | 127 | 6/2/2026 |
| 13.4.0-beta.671 | 47 | 7/3/2026 |
| 13.4.0-beta.654 | 58 | 6/18/2026 |
| 13.4.0-beta.651 | 59 | 6/17/2026 |
| 13.3.0 | 150 | 5/14/2026 |
| 13.2.1-beta.604 | 57 | 5/14/2026 |
| 13.2.1-beta.532 | 77 | 3/13/2026 |
| 13.2.1-beta.531 | 73 | 3/11/2026 |
| 13.2.1-beta.528 | 67 | 3/5/2026 |
| 13.1.2-beta.518 | 77 | 2/17/2026 |
| 13.1.2-beta.516 | 77 | 2/9/2026 |
| 13.1.2-beta.515 | 75 | 2/2/2026 |
| 13.1.2-beta.514 | 75 | 1/30/2026 |
| 13.1.2-beta.513 | 76 | 1/29/2026 |