我正在尝试做一个SSH隧道应用程序。我成功地打开了一个带有动态端口的隧道,它一直工作到第一个浏览器连接完成为止。加载一个页面后,隧道不再工作,在重新启动隧道之前,我无法打开下一页。有时会有例外
“对象引用未设置为对象的实例。”"System.NullReferenceException“在Renci.SshNet.dll。
我的代码如下:
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();
}它有什么问题?你能帮我使我的应用程序工作吗?事先非常感谢!
发布于 2015-06-30 10:29:49
解决方案:不要使用SSH.net从NuGet,使用最新的版本从他们的网站,有不同的版本。最后一个很好用。
https://stackoverflow.com/questions/31105470
复制相似问题