Hi,
Could you please let us know how to reproduce the issue with a ignored root folder? This is working fine here, and none of our unit tests detected any similar issue on any of the supported platforms.
What should this put
command actually do? There is no put
shell command in OS X, Linux or Windows. On the other hand, if you intend to upload files, you are supposed to use an SCP or SFTP client (which does provide a put
command at the client side).
You can easily limit the server to only accept connections from localhost by binding to the machine's loopback address. Just call server.Bind(new IPEndPoint(IPAddress.Loopback, port), FileServerProtocol.Sftp)
instead of server.Bind(port, FileServerProtocol.Sftp)
(where server
is an instance of FileServer
). Alternatively, if you would rather allow/reject connections based on
an IP address whitelist, use FileServer
object's Connecting
event.
A simple code to achieve this (IP-address-based accept/reject event not included) might look like this:
// create a server instance
var server = new FileServer();
// bind SFTP to port 2222 (all interfaces)
server.Bind(2222, FileServerProtocol.Sftp);
// bind shell to port 2222 (all interfaces)
server.Bind(2222, FileServerProtocol.Shell);
// bind SFTP to port 2222 of localhost
//server.Bind(new IPEndPoint(IPAddress.Loopback, 2222), FileServerProtocol.Sftp);
// bind shell to port 2222 of localhost
//server.Bind(new IPEndPoint(IPAddress.Loopback, 2222), FileServerProtocol.Shell);
// load a server private key from encrypted 'server-key.ppk' file
if (!System.IO.File.Exists("server-key.ppk"))
{
// generate a 1024bit RSA key pair
var privateKey = SshPrivateKey.Generate(SshHostKeyAlgorithm.RSA, 1024);
// save the private key in PuTTY format
privateKey.Save(@"server-key.ppk", "key_password", SshPrivateKeyFormat.Putty);
}
// specify a server key
server.Keys.Add(new SshPrivateKey("server-key.ppk", "key_password"));
// add a user (specify username, password and virtual root path)
server.Users.Add("user01", "password", @"/Users/test/ServerRoot");
Console.WriteLine("Starting server...");
Console.WriteLine("Use user01/password to login to the server");
Console.WriteLine();
// start the server in the background
server.Start();
Console.WriteLine("To stop the server, press Enter.");
Console.ReadLine();
server.Stop();
You can download a whole solution here.