Skip to content

filipetoscano/sftpgo.net

Repository files navigation

SftpGo

CI NuGet License: MIT

.NET client for SftpGo, an SFTP server, written in C#.

Functionality

The SftpGoClient supports the following objects (and methods):

  • ApiKeys (List, Create, Delete)
  • Users (List, Get, Create, Update, Delete, Enable, Disable)
  • Event Rules (List, Get, Create, Update, Delete, Enable, Disable)
  • Event Actions (List, Get, Create, Update, Delete)
  • Version (Get)
  • Service Status (Get)

Installing via NuGet

Package is published in the NuGet gallery.

From the command-line:

> dotnet add package SftpGo

From within Visual Studio using Package Manager Console:

PM> Install-Package SftpGo

Getting started

In the startup of your application, configure the DI container as follows:

using SftpGo;

builder.Services.AddOptions();
builder.Services.AddHttpClient<SftpGoClient>();
builder.Services.Configure<SftpGoClientOptions>( o =>
{
    o.ApiUrl = Environment.GetEnvironmentVariable( "SFTPGO_APIURL" )!;
    o.ApiKey = Environment.GetEnvironmentVariable( "SFTPGO_APIKEY" );
} );
builder.Services.AddTransient<ISftpGo, SftpGoClient>()

Auth: Mostly API key, but sometimes AuthToken

Most objects in the REST API can use an API key, but there are a few objects (namely API Keys) which can only be invoked using an Access Token. Moreover, the SFTPGo admin web application does not currently implement any UI to manage API keys. The only manner is through the REST API.

As such, the necessary flow is as follows:

  • In SFTPGo admin web, go to the admin user and check the "API key authentication" option. This will allow the use of API keys associated with that admin user
  • Authenticate as an admin (using username/password/OTP), using Authenticate
  • Set the access token on the client instance, using UseAuthToken
  • Create an API key, using ApiKeyCreate
  • Persist the API key: it is only visible once -- as a result of key create operation
  • Set the API key on the client instance, using UseApiKey
  • Use the rest of the API (e.g. users, services, etc)