ruby - How to SSH into a server and then SFTP from there to another server? -
here's situation:
i have ssh access servera
i have sftp access serverb, servera
i want use ruby ssh servera, sftp files serverb servera.
i can connect servera using documentation net::ssh:
require 'net/ssh/gateway' gateway = net::ssh::gateway.new('server_a', 'user') gateway.ssh("server_a", "user") |ssh| # how sftp server_b here , run sftp commands? end gateway.shutdown!
what can't figure out how sftp serverb context of servera?
assuming have private keys setup, run:
$ ssh-add
and write this:
require 'net/ssh' # set :forward_agent => true automatically authenticate server_b net::ssh.start('server_a', 'user', :forward_agent => true) |ssh| puts ssh.exec!("scp -r server_b:dir_i_want_to_copy dir_to_copy_to/") end
Comments
Post a Comment