Back to feature list...
SFTP server
On this page:
Rebex File Server can be used to easily add SFTP server capabilities to your .NET application, no matter whether you use C#, VB.NET or any other .NET language.
Launching an SFTP server
Simply create an instance of
FileServer,
bind it to a port, add a private key and at least one user with a path to their root directory.
Then start it, and the fully working SFTP server is ready:
// create a server instance
var server = new FileServer();
// bind SFTP (runs over SSH) to port 22
server.Bind(22, FileServerProtocol.Sftp);
// load a server private key from encrypted 'serverkey.ppk' file
server.Keys.Add(new SshPrivateKey("server-key.ppk", "password"));
// add a user (specify username, password and virtual root path)
server.Users.Add("user01", "password", @"c:\data\user01");
// start the server in the background
server.Start();
' create a server instance
Dim server = New FileServer()
' bind SFTP (runs over SSH) to port 22
server.Bind(22, FileServerProtocol.Sftp)
' load a server private key from encrypted 'serverkey.ppk' file
server.Keys.Add(New SshPrivateKey("server-key.ppk", "password"))
' add a user (specify username, password and virtual root path)
server.Users.Add("user01", "password", "c:\data\user01")
' start the server in the background
server.Start()
See also
SFTP v3 and v4
Rebex File Server supports SFTP v3 (the most commonly supported version of SFTP) and a subset of SFTP v4 (which adds some useful features).
Virtual file system
Rebex File Server presents a virtual file system to each user. This makes it simple to configure it so that no sensitive or unwanted data are revealed - just confine each user to a specific directory (and its subtree) in the filesystem.
Tracking uploads and downloads
Rebex File Server enables tracking of uploaded and downloaded files.
To get notified when a file is uploaded or downloaded, register
FileServer.FileUploaded event or
FileServer.FileDownloaded event, respectively.
server.FileUploaded += server_FileUploaded; server.FileDownloaded += server_FileDownloaded;
AddHandler server.FileUploaded, AddressOf Me.server_FileUploaded AddHandler server.FileDownloaded, AddressOf Me.server_FileUploaded
Both events provide various information about the transfer, such as details about the user transferring the file, relative path from the user's root directory, bytes transferred, and so on.
void server_FileDownloaded(object sender, FileTransferredEventArgs e)
{
Console.WriteLine("User '{0}' downloaded file '{1}', bytes transferred: {2}",
e.User.Name, e.FullPath, e.BytesTransferred);
}
void server_FileUploaded(object sender, FileTransferredEventArgs e)
{
Console.WriteLine("User '{0}' uploaded file '{1}', bytes transferred: {2}",
e.User.Name, e.FullPath, e.BytesTransferred);
}
Private Sub server_FileDownloaded(ByVal sender As Object, ByVal e As FileTransferredEventArgs)
Console.WriteLine("User '{0}' downloaded file '{1}', bytes transferred: {2}",
e.User.Name, e.FullPath, e.BytesTransferred)
End Sub
Private Sub server_FileUploaded(ByVal sender As Object, ByVal e As FileTransferredEventArgs)
Console.WriteLine("User '{0}' uploaded file '{1}', bytes transferred: {2}",
e.User.Name, e.FullPath, e.BytesTransferred)
End Sub
Server-side file hash calculation
Rebex File Server supports the check-file
protocol extension
that makes it possible for SFTP clients to request the server to calculate a hash of a specified file or a part of it.
The client can then compare the server's hash value with the hash of a loacl file to determine whether the files are identical.
See how to use hashing on the SFTP client side with Rebex SFTP library.
Server-side file copying
Rebex File Server supports the copy-data
protocol extension,
which makes it possible for compatible SFTP clients to copy files directly on the server without having
to download and upload the data again. This reduces network traffic and speeds up remote file copies,
especially for large files.
The extension can be used, for example, with the copy command in the OpenSSH SFTP client.
Compatible with popular SFTP clients
Our SFTP server is compatible with popular third-party SFTP clients such as WinSCP,
FileZilla, OpenSSH's sftp command.
It's a perfect companion to our SFTP client library, but it works with any third-party client that supports SSH2 and SFTP v3 or SFTP v4.
Back to feature list...