我正在尝试使用SSH.NETlocalhost:3306
在远程计算机上创建从端口 3306 到端口的隧道:
PrivateKeyFile file = new PrivateKeyFile(@" .. path to private key .. ");
using (var client = new SshClient(" .. remote server .. ", "ubuntu", file))
{
client.Connect();
var port = new ForwardedPortLocal(3306, "localhost", 3306);
client.AddForwardedPort(port);
port.Start();
// breakpoint set within the code here
client.Disconnect();
}
当断点被命中时,client.IsConnected
正在返回true
,但telnet localhost 3306
没有连接。如果我使用 Putty 创建连接,并在那里设置相同的隧道,它会成功。我错过了什么?