Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby NET::SCP and custom ports

Tags:

port

ssh

ruby

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

like image 754
ghostrifle Avatar asked Mar 15 '11 09:03

ghostrifle


2 Answers

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
like image 61
ghostrifle Avatar answered Oct 24 '22 05:10

ghostrifle


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.

like image 40
Golden Flying Broom Avatar answered Oct 24 '22 06:10

Golden Flying Broom