SFTPServer 1.3.3

dotnet add package SFTPServer --version 1.3.3                
NuGet\Install-Package SFTPServer -Version 1.3.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SFTPServer" Version="1.3.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SFTPServer --version 1.3.3                
#r "nuget: SFTPServer, 1.3.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SFTPServer as a Cake Addin
#addin nuget:?package=SFTPServer&version=1.3.3

// Install SFTPServer as a Cake Tool
#tool nuget:?package=SFTPServer&version=1.3.3                

SFTPServer

This library (and simple host) implement an SFTP server that implements the V3 version of the SFTP protocol and is available as NuGet package.

This library is intended to be hosted in an SSH deamon; this can be done by editting the sshd_config file (usually in /etc/ssh/ or, for Windows, in %PROGRAMDATA%\ssh) and pointing it to your own host executable.

In sshd_config you'll find the Subsystem entry which can be pointed to any executable:

# override default of no subsystems
#Subsystem	sftp	sftp-server.exe
#Subsystem	sftp	internal-sftp
Subsystem	sftp	/path/to/your/sftphost.exe

The way SFTP works is that first an SSH connection is established; once that is done and a request is made for sftp, SSH will launch the configured executable under the connected user's account. All communication is done over stdin and stdout. The SFTPServer class takes 2 Streams and optionally an ISFTPHandler on which the SFTP commands will be invoked. This package comes with a DefaultSFTPHandler which provides basic I/O on the hosts's filesystem (based on a rootdirectory), but it should be pretty easy to implement your own ISFTPHandler so you can, for example, implement a virtual filesystem.

The SFTPHost project in this repository demonstrates how to simply build an executable that hosts an SFTPServer instance. A new SFTPServer is launched by the SSH service for each connection.

Implementing an ISFTPHandler

Implementing an ISFTPHandler should be pretty straightforward, simply implement the ISFTPHandler interface. Exceptions you might want to throw should, ideally, be inherited from the HandlerException. This library comes with a few built-in exceptions in the SFTP.Exceptions namespace. Exceptions that are not inherited from the HandlerException will be returned to the client as Failure (SSH_FX_FAILURE). For an example implementation you can have a look at the DefaultSFTPHandler.

Known issues and limitations

  • Note that this library only implements V3; higher versions are not supported. Clients connecting with a higher version will be negotiated down to V3.

  • The SymLink command has been implemented with the linkpath and targetpath swapped; We may or may not interpret the RFC incorrectly (Update: We didn't) or the clients which were used to test the SymLink command (WinSCP, Cyberduck and the 'native' sftp commandline executable) had the arguments swapped. The SymLink and ReadLink methods are only available from .Net 6.0 upwards.

  • The DefaultSFTPHandler DOES NOT take particular much care of path canonicalization or mitigations against path traversion. When used in an untrusted environment extra care should be taken to ensure safety.

  • The DefaultSFTPHandler DOES NOT make a noteworthy effort to return correct POSIX file permissions, nor does it support setting permissions.

License

Licensed under MIT license. See LICENSE for details.

Attributions

Logo / icon by Alexiuz AS (Archived)

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.3 855 8/5/2022
1.3.2 419 5/30/2022
1.3.1 410 5/25/2022
1.3.0 427 5/24/2022
1.2.1 414 5/23/2022
1.2.0 413 5/23/2022
1.1.0 410 5/23/2022
1.0.2 424 5/23/2022
1.0.0 432 5/20/2022

Initial release