2011-03-15 80 views
6

我正在尝试使用Net :: SCP为ssh连接定义自定义端口,但目前为止还没有成功。Ruby NET :: SCP和自定义端口

这里是如何,我试图从服务器下载远程文件与自定义SSH端口一个例子:

require "rubygems" 
require 'net/scp' 
Net::SCP.download!("www.server.com", "user", "/opt/platform/upload/projects/file.txt", "/tmp/bb.pdf",{:password => "mypassword",:port => 22202}) 

我得到的错误信息是:

Errno::ECONNREFUSED: Connection refused - connect(2) 

有在服务器日志中没有关于ssh连接的条目,所以我假设Net :: SCP没有使用我的自定义端口。

我的任何提示?

问候,亚历克斯

回答

9

嗯,我已经找到了解决方案本人。

require "rubygems" 
require "net/scp" 
Net::SSH.start("www.myserver.com", "theuser", {:password => "whateverpwd",:port => 22212}) do |ssh| 
    ssh.scp.download! "/opt/platform/upload/projects/my.pdf", "/tmp/bb.pdf" 
end 
2

我还留着一个SSH非标准端口上使用SCP,像这样:

Net::SCP.upload!("foo.net", "user", the_file, the_file, :ssh => { :keys => @keys, :port => the_port }) 

作品就像一个冠军。我也使用基于密钥的身份验证,因此密钥参数与端口一起传递。

+0

变量@keys如何设置? – RNickMcCandless 2014-11-26 01:56:30