Get started with the SFTP integration
Konten ini belum tersedia dalam bahasa Anda.
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.
Prerequisites
Section titled “Prerequisites”- An Aspire AppHost project
- An SFTP username and password or an SSH public/private key pair
Add an SFTP server
Section titled “Add an SFTP server”Install 📦 CommunityToolkit.Aspire.Hosting.Sftp in the AppHost. Configure users with a file named users.conf:
fileuser:__PASSWORD_HASH__:e:::uploadsThe 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.
aspire add CommunityToolkit.Aspire.Hosting.Sftpimport { 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();aspire add CommunityToolkit.Aspire.Hosting.Sftpvar builder = DistributedApplication.CreateBuilder(args);var sftp = builder.AddSftp("sftp") .WithUsersFile("users.conf");
builder.AddProject<Projects.Worker>("worker") .WithReference(sftp);
// After adding all resources, run the app...builder.Build().Run();Connect from a .NET app
Section titled “Connect from a .NET app”Install 📦 CommunityToolkit.Aspire.Sftp in the consuming project and register a client with the same connection name:
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.