Rebex File Server
SFTP, SCP and SSH server library for .NET
Download 30-day free trial Buy from $349More .NET libraries
-
Rebex SFTP
.NET SFTP client
-
Rebex FTP
.NET FTP client
-
Rebex Total Pack
All Rebex libraries together
Back to feature list...
Easy-to-use API
Launching an SFTP server
With Rebex File Server, launching a fully working SFTP server is just a matter of several lines of code.
Simply create an instance of FileServer
, bind it to a port, add a private key and at least one user. Then the server is ready:
// create a server instance
var server = new FileServer();
// use console log writer
server.LogWriter = new ConsoleLogWriter(LogLevel.Debug);
// 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()
' use console log writer
server.LogWriter = New ConsoleLogWriter(LogLevel.Debug)
' 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()
Configuring the server
Need a more advanced configuration? Or perhaps SCP support?
FileServer
is very configurable and supports various kinds of options:
// create a server instance
var server = new FileServer();
// use console-based log writer
server.LogWriter = new ConsoleLogWriter(LogLevel.Debug);
// or a file-based log writer
//server.LogWriter = new FileLogWriter(@"c:\data\server.log", LogLevel.Debug);
// bind SFTP and virtual shell subsystems (both run over SSH) to port 22
server.Bind(22, FileServerProtocol.Sftp);
server.Bind(22, FileServerProtocol.Shell);
// load server private keys (RSA and DSA)
server.Keys.Add(new SshPrivateKey("server-key-rsa.ppk", "password"));
server.Keys.Add(new SshPrivateKey("server-key-dsa.ppk", "password"));
// add users
server.Users.Add("user01", "password01", @"c:\data\user01");
server.Users.Add("user02", "password02", @"c:\data\user02");
// only allow AES-based ciphers
server.Settings.SshParameters.EncryptionAlgorithms = SshEncryptionAlgorithm.AES;
// set a banner to send to the client before authentication
server.Settings.Banner = "This is a sample SFTP and SCP server.";
// set maximum number of authentication attempts for a single connection
server.Settings.MaxAuthenticationAttempts = 5;
// start the server in the background
server.Start();
// wait for a keypress
Console.WriteLine("Press any key to exit.");
Console.ReadKey(true);
// stop the server
server.Stop();
' create a server instance
Dim server = New FileServer()
' use console-based log writer
server.LogWriter = New ConsoleLogWriter(LogLevel.Debug)
' or a file-based log writer
'server.LogWriter = new FileLogWriter(@"c:\data\server.log", LogLevel.Debug);
' bind SFTP and virtual shell subsystems (both run over SSH) to port 22
server.Bind(22, FileServerProtocol.Sftp)
server.Bind(22, FileServerProtocol.Shell)
' load server private keys (RSA and DSA)
server.Keys.Add(New SshPrivateKey("server-key-rsa.ppk", "password"))
server.Keys.Add(New SshPrivateKey("server-key-dsa.ppk", "password"))
' add users
server.Users.Add("user01", "password01", "c:\data\user01")
server.Users.Add("user02", "password02", "c:\data\user02")
' only allow AES-based ciphers
server.Settings.SshParameters.EncryptionAlgorithms = SshEncryptionAlgorithm.AES
' set a banner to send to the client before authentication
server.Settings.Banner = "This is a sample SFTP and SCP server."
' set maximum number of authentication attempts for a single connection
server.Settings.MaxAuthenticationAttempts = 5
' start the server in the background
server.Start()
' wait for a keypress
Console.WriteLine("Press any key to exit.")
Console.ReadKey(True)
' stop the server
server.[Stop]()
Generating private keys
Generating private keys for your server is simple as well:
// generate and save a 2048-bit RSA key
SshPrivateKey rsaKey = SshPrivateKey.Generate(SshHostKeyAlgorithm.RSA, 2048);
rsaKey.Save("server-key-rsa.ppk", "password", SshPrivateKeyFormat.Putty);
// save a corresponding public key as well (optional)
rsaKey.SavePublicKey("server-key-rsa.pub", SshPublicKeyFormat.Ssh2Base64);
// generate and save 1024-bit DSA key
SshPrivateKey dsaKey = SshPrivateKey.Generate(SshHostKeyAlgorithm.DSS, 1024);
dsaKey.Save("server-key-dsa.ppk", "password", SshPrivateKeyFormat.Putty);
// save a corresponding public key as well (optional)
rsaKey.SavePublicKey("server-key-dsa.pub", SshPublicKeyFormat.Ssh2Base64);
' generate and save a 2048-bit RSA key
Dim rsaKey As SshPrivateKey = SshPrivateKey.Generate(SshHostKeyAlgorithm.RSA, 2048)
rsaKey.Save("server-key-rsa.ppk", "password", SshPrivateKeyFormat.Putty)
' save a corresponding public key as well (optional)
rsaKey.SavePublicKey("server-key-rsa.pub", SshPublicKeyFormat.Ssh2Base64)
' generate and save 1024-bit DSA key
Dim dsaKey As SshPrivateKey = SshPrivateKey.Generate(SshHostKeyAlgorithm.DSS, 1024)
dsaKey.Save("server-key-dsa.ppk", "password", SshPrivateKeyFormat.Putty)
' save a corresponding public key as well (optional)
rsaKey.SavePublicKey("server-key-dsa.pub", SshPublicKeyFormat.Ssh2Base64)
The server keys are used to validate the server to its clients. They are not supposed to change. The private keys should be only accessible by the server. On the other hand, public keys can be shared with third parties.
Back to feature list...