Skip to content

mikaelliljedahl/freesftpsharp

Repository files navigation

SftpServer (SSHServer)

Sftp Server implementation based on SSHServer library based heavily on FxSsh. This fork (based on https://github.com/0xFireball/SSHServer) implements the sftp subsystem and a Graphical user interface for administration of users and server settings.

Current status

All basic Sftp command are now implemented except handling symbolic links. However some implementations such as returning correct file attributes are not finalized. Server was tested with FileZilla client only. There are probably some bugs left to fix. You are welcome to create PR's

FxSsh

FxSsh is a lightweight SSH server side application as SSH reinforcement of GitCandy.

Features in this repo that was not in the original FxSSH

  • Password Authentication is implemented and enabled by default
  • Public Key authentication relying on key fingerprint
  • Server key is autogenerated at first startup time
  • Logging based on Serilog.
  • SFTP subsystem added.
  • Running commands remotely is disabled by default (code is commented out but will later be a setting per user)
  • Server is started using IHostedService interface (useful for standalone service or hosted inside Asp.Net Core)
  • Server settings are saved in a LiteDb-database file.

Features planned for the future

  • whitelist IP/ip-range (CIDR) per account. (Implemented in server but not in the admin UI)
  • Ban IP, auto-ban on multiple failed attempts to login
  • Option to use cloud Blob storage as sftp root. Filesystem will be an interface in the SFTP engine, then both local file system or blob storage can be used. Controlled using Dependency Injection
  • Different ways to store settings and users (using Dependency Injection). E.g. Azure SQL, SQLite, JSON, LiteDb
  • SCP subsystem

Sample

Server (Powered by this library)

using FxSsh;
using FxSsh.Services;
using System;
using System.Text;
using System.Threading.Tasks;

namespace SshServerLoader
{
    class Program
    {
         static async Task Main(string[] args)
        {
             await new HostBuilder()
            .ConfigureServices((hostContext, services) =>
            {
                services.AddLogging();
                Log.Information("Starting host service");
                services.AddHostedService<HostedSftpServer>();
            })
            .RunConsoleAsync();
        }
    }
}

Client (powered by SSH.NET client)

using Renci.SshNet;
using System;
using System.Net;

namespace TestClient
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var testUsername = "test_person";
            var testPassword = "1234";


            var connInfo = new ConnectionInfo(IPAddress.Loopback.ToString(), 22, testUsername,
                new AuthenticationMethod[]
                {
                    // Password auth
                    new PasswordAuthenticationMethod(testUsername, testPassword)
                }
            );

            using var sftpclient = new SftpClient(connInfo);
            sftpclient.Connect();
            sftpclient.ListDirectory("/");
            sftpclient.Disconnect();
            
            Console.ReadLine();
        }
    }
}

License

The MIT license

About

SFTP server with Web Admin GUI based on FxSSH

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published