简体   繁体   English

SSH.Net隧道

[英]SSH.Net Tunneling

I am trying to make a SSH Tunnel application. 我正在尝试制作SSH隧道应用程序。 I successfully open a tunnel with dynamic port and it works until the first connection by browser is made. 我成功地打开了一个带有动态端口的隧道,该隧道在浏览器建立第一个连接之前一直有效。 After one page is loaded, the tunnel is not working anymore and I unable to open next page until I restart a tunnel. 加载一页后,隧道不再工作,并且在重新启动隧道之前无法打开下一页。 Sometimes there is an exception 有时会有例外

"Object reference not set to an instance of the object." “对象引用未设置为对象的实例。” "System.NullReferenceException" in Renci.SshNet.dll. Renci.SshNet.dll中的“ System.NullReferenceException”。

My code is following: 我的代码如下:

SshClient client;
ForwardedPortDynamic port;

public void Start(string server, string user, string password, int serverport=22)
{
        client = new SshClient(server, user, password);
        client.KeepAliveInterval = new TimeSpan(0, 0, 5);
        client.ConnectionInfo.Timeout = new TimeSpan(0, 0, 20);
        client.Connect();

        if (client.IsConnected)
        {
            try
            {
                port = new ForwardedPortDynamic("127.0.0.1", 1080);
                client.AddForwardedPort(port);
                port.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

}

public void Stop()
{
    port.Stop();
    port.Dispose();
    client.Disconnect();
    client.Dispose();
}

What's wrong with it? 它出什么问题了? Could you please help me make my app work! 您能否帮我使我的应用程序正常工作! Many thanks in advance! 提前谢谢了!

Solution: don't use SSH.net from NuGet, use the latest version from their website, there are different versions. 解决方案:不要使用来自NuGet的SSH.net,请使用其网站上的最新版本,有不同的版本。 The last one is working good. 最后一个工作良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM