0 votes
by (120 points)

1 Answer

0 votes
by (150k points)

public static void Main()
{
    // port to listen at
    int port = 8022;

    // server's private key
    var key = new SshPrivateKey("key.ppk", "password");

    // set up a user with one of several file system providers
    var user01 = new FileServerUser("user01", "password", @"\Hard Disk\SFTP\user01");

    // create a server instance
    var server = new FileServer();

    // bind SFTP/SSH and SSH shell to port 8022
    server.Bind(port, FileServerProtocol.Sftp);
    server.Bind(port, FileServerProtocol.Shell);

    // add server key
    server.Keys.Add(key);

    // add a user
    server.Users.Add(user01);

    // use console log writer
    server.LogWriter = new ConsoleLogWriter(LogLevel.Info);

    // start server in the background
    server.Start();

    // run the server
    Console.WriteLine("Server is listening at port {0}", port);
    Console.WriteLine("Press 'Enter' to stop.");
    Console.ReadLine();

    // stop the server
    server.Stop();
    Console.WriteLine("Server has been stopped.");
}

...