Get started with the SFTP integration

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

⭐ Community Toolkit

The Community Toolkit SFTP integrations provide an atmoz SFTP container resource and a .NET client based on SSH.NET. Use the host integration to configure an SFTP server and the client integration to register SftpClient in a consuming app.

  • An Aspire AppHost project
  • An SFTP username and password or an SSH public/private key pair

Install 📦 CommunityToolkit.Aspire.Hosting.Sftp in the AppHost. Configure users with a file named users.conf:

users.conf
fileuser:__PASSWORD_HASH__:e:::uploads

The user-file format is username:password[:e[:uid[:gid[:dir1[,dir2]...]]]]. The e marker identifies an encrypted password. See Set up the SFTP resource for key-based access and host key configuration.

Terminal
aspire add CommunityToolkit.Aspire.Hosting.Sftp
apphost.mts
import { createBuilder } from './.aspire/modules/aspire.mjs';
const builder = await createBuilder();
const sftp = await builder.addSftp('sftp');
await sftp.withUsersFile('./users.conf');
const worker = await builder.addProject('worker', '../Worker/Worker.csproj');
await worker.withReference(sftp);
await builder.build().run();

Install 📦 CommunityToolkit.Aspire.Sftp in the consuming project and register a client with the same connection name:

Program.cs
builder.AddSftpClient(
"sftp",
settings =>
{
settings.Username = "fileuser";
settings.Password = builder.Configuration["Sftp:Password"];
});

For the configuration options, authentication methods, and file transfer example, see Connect to an SFTP server.