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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With