我正在使用 Windows 框中的本地到远程端口转发访问远程数据库。它使用腻子进行端口转发就像一个魅力,但是当我尝试使用 Ruby/Net::SSH 转发时它失败了。这是我的代码片段:
require 'rubygems'
require 'net/ssh'
Net::SSH.start(remote_host, user_name, :password => password) do |ssh|
ssh.logger.sev_threshold=Logger::Severity::DEBUG
ssh.forward.local(5555, 'www.google.com', 80) # works perfectly
ssh.forward.local(4444, remote_host, 1234) # db connection hangs up
ssh.loop { true }
end
使用浏览器测试时,转发到 google.com 的端口可以正常工作。转发到我的 db 服务器正在侦听端口 1234 的 linux 服务器的端口不起作用。当我尝试连接到 localhasot:4444 时,连接挂断了。日志:
DEBUG -- net.ssh.service.forward[24be0d4]: received connection on 127.0.0.1:4444
DEBUG -- tcpsocket[253ba08]: queueing packet nr 6 type 90 len 76
DEBUG -- tcpsocket[24bde64]: read 8 bytes
DEBUG -- tcpsocket[253ba08]: sent 100 bytes
DEBUG -- net.ssh.connection.channel[24bdcc0]: read 8 bytes from client, sending over local forwarded connection
然后什么都没有!
我正在使用 net-ssh 2.0.22 / ruby 1.8.7