Set up SFTP with the Aspire integration

이 콘텐츠는 아직 번역되지 않았습니다.

⭐ Community Toolkit

Use the SFTP hosting integration to run the atmoz SFTP server as a container resource. For a first walkthrough that includes its paired .NET client, see Get started with the SFTP integration.

Aspire CLI — CommunityToolkit.Aspire.Hosting.Sftp 패키지 추가
aspire add communitytoolkit-sftp

Aspire CLI는 대화형입니다. 프롬프트 시 알맞은 검색 결과 선택:

Aspire CLI — 출력 예시
Select an integration to add:
> communitytoolkit-sftp (CommunityToolkit.Aspire.Hosting.Sftp)
> Other results listed as selectable options...

The WithUsersFile method mounts a user configuration file into the container. Its lines use the format username:password[:e[:uid[:gid[:dir1[,dir2]...]]]].

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

The e marker denotes an encrypted password. You can also configure users through container arguments or the SFTP_USERS environment variable. Avoid committing plaintext passwords to the AppHost project.

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();

The resource exposes an SFTP connection URI in the form sftp://host:port. Use the same resource name in the consuming app’s client registration.

Use WithUserKeyFile to mount a public key for a user. The corresponding private key stays with the client. WithHostKeyFile mounts a stable server host key so container recreation does not cause clients to see a changed host identity.

AppHost.cs
var sftp = builder.AddSftp("sftp")
.WithUsersFile("users.conf")
.WithUserKeyFile("fileuser", "fileuser-ed25519.pub", KeyType.Ed25519)
.WithHostKeyFile("ssh_host_ed25519_key", KeyType.Ed25519);

The host-key and user-key files must exist at the paths supplied to the AppHost. Do not mount a private user key into the server container.

MethodPurpose
AddSftp / addSftpAdd the SFTP container and optionally set its host port.
WithUsersFile / withUsersFileConfigure users from a file.
WithUserKeyFile / withUserKeyFileAdd a public key for an SFTP user.
WithHostKeyFile / withHostKeyFileUse a stable SSH server host key.