开发者

Ruby NET::SCP and custom ports

I'm trying to define a custom port for the ssh connection using Net::SCP, but without luck so far.

开发者_运维百科Here's an example how I'm trying to download a remote file from a server with a custom ssh port:

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})

The error message I'm getting is:

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

There are no entries in the server logs regarding the ssh connection, so I assume that Net::SCP isn't using my custom port.

Any tips for me ?

Regards, Alex


Well, I've found the solution myself.

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


I also keep SSH on a non-standard port and use SCP like so:

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

Works like a champ. I also use key-based authentication, hence the keys parameter getting passed along with the port.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜