# SftpHostingExtensions Methods

- Package: [CommunityToolkit.Aspire.Hosting.Sftp](/reference/api/csharp/communitytoolkit.aspire.hosting.sftp.md)
- Type: [SftpHostingExtensions](/reference/api/csharp/communitytoolkit.aspire.hosting.sftp/sftphostingextensions.md)
- Kind: `Methods`
- Members: `4`

Provides extension methods for adding an SFTP resource to an `Hosting.IDistributedApplicationBuilder`.

## AddSftp(IDistributedApplicationBuilder, string, int?)

- Name: `AddSftp(IDistributedApplicationBuilder, string, int?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<SftpContainerResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Sftp/SftpHostingExtensions.cs#L37-L51)

Adds atmoz SFTP to the application model.

```csharp
public static class SftpHostingExtensions
{
    public static IResourceBuilder<SftpContainerResource> AddSftp(
        this IDistributedApplicationBuilder builder,
        string name,
        int? port = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The `Hosting.IDistributedApplicationBuilder` to add the resource to.
- `name` (`string`)
  The name of the resource.
- `port` (`int?`) `optional`
  The SFTP port number for the atmoz SFTP container.

## Returns

`IResourceBuilder<SftpContainerResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

Add an SFTP container to the application model with users configuration in the specified file.

```csharp
var builder = DistributedApplication.CreateBuilder(args);

builder.AddSftp("sftp");

builder.Build().Run();
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithHostKeyFile(IResourceBuilder<SftpContainerResource>, string, KeyType)

- Name: `WithHostKeyFile(IResourceBuilder<SftpContainerResource>, string, KeyType)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<SftpContainerResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Sftp/SftpHostingExtensions.cs#L109-L129)

Adds a bind mount for the specified host key file to an SFTP container resource.

```csharp
public static class SftpHostingExtensions
{
    public static IResourceBuilder<SftpContainerResource> WithHostKeyFile(
        this IResourceBuilder<SftpContainerResource> builder,
        string keyFile,
        KeyType keyType)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<SftpContainerResource>`)
  The resource builder.
- `keyFile` (`string`)
  The path to the host key file.
- `keyType` ([KeyType](/reference/api/csharp/communitytoolkit.aspire.hosting.sftp/keytype.md))
  The type of the host key.

## Returns

`IResourceBuilder<SftpContainerResource>` -- The `ApplicationModel.IResourceBuilder`1`.

## Remarks

Add an SFTP container to the application model with the host key in the specified file.

```csharp
var builder = DistributedApplication.CreateBuilder(args);

builder.AddSftp("sftp").WithHostKeyFile("./etc/ssh/ssh_host_ed25519_key", KeyType.Ed25519);

builder.Build().Run();
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithUserKeyFile(IResourceBuilder<SftpContainerResource>, string, string, KeyType)

- Name: `WithUserKeyFile(IResourceBuilder<SftpContainerResource>, string, string, KeyType)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<SftpContainerResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Sftp/SftpHostingExtensions.cs#L155-L165)

Adds a bind mount for the public key file of the specified user to an SFTP container resource.

```csharp
public static class SftpHostingExtensions
{
    public static IResourceBuilder<SftpContainerResource> WithUserKeyFile(
        this IResourceBuilder<SftpContainerResource> builder,
        string username,
        string keyFile,
        KeyType keyType)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<SftpContainerResource>`)
  The resource builder.
- `username` (`string`)
  The user whose public key is being bind mounted
- `keyFile` (`string`)
  The public key file of the specified user (will be bind mounted on the server).
- `keyType` ([KeyType](/reference/api/csharp/communitytoolkit.aspire.hosting.sftp/keytype.md))
  The type of the host key.

## Returns

`IResourceBuilder<SftpContainerResource>` -- The `ApplicationModel.IResourceBuilder`1`.

## Remarks

Add an SFTP container to the application model with the host key in the specified file.

```csharp
var builder = DistributedApplication.CreateBuilder(args);

builder.AddSftp("sftp").WithUserKeyFile("foo", "./home/foo/.ssh/keys/id_rsa.pub", KeyType.Rsa);

builder.Build().Run();
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithUsersFile(IResourceBuilder<SftpContainerResource>, string)

- Name: `WithUsersFile(IResourceBuilder<SftpContainerResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<SftpContainerResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Sftp/SftpHostingExtensions.cs#L75-L84)

Adds a bind mount for the users.conf file to an SFTP container resource.

```csharp
public static class SftpHostingExtensions
{
    public static IResourceBuilder<SftpContainerResource> WithUsersFile(
        this IResourceBuilder<SftpContainerResource> builder,
        string usersFile)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<SftpContainerResource>`)
  The resource builder.
- `usersFile` (`string`)
  The path to the users.conf file.

## Returns

`IResourceBuilder<SftpContainerResource>` -- The `ApplicationModel.IResourceBuilder`1`.

## Remarks

Add an SFTP container to the application model with users configuration in the specified file.

```csharp
var builder = DistributedApplication.CreateBuilder(args);

builder.AddSftp("sftp").WithUsersFile("./etc/sftp/users.conf");

builder.Build().Run();
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
