.NET SSH port forwarding

前端 未结 5 962
长发绾君心
长发绾君心 2020-12-28 09:52

I am trying to build in SSH port forwarding into a .NET application that I am writing.

I have tried using sharpSSH, but it requires the user to input their password

5条回答
  •  醉梦人生
    2020-12-28 10:36

    The SSH.NET library is a simple way to achieve this:

    using (var client = new SshClient("client.net", "user", "password"))
    {
        client.Connect();
    
        var port = new ForwardedPortLocal("localhost", 10000, "remote.net", 80);
        client.AddForwardedPort(port);
    
        port.Exception += delegate(object sender, ExceptionEventArgs e)
        {
            Console.WriteLine(e.Exception.ToString());
        };
        port.Start();
    
        // ... hold the port open ... //
    
        port.Stop();
        client.Disconnect();
    }
    

提交回复
热议问题