I have a file in the directory usr/share/ruby.rb
. I want to transfer that file to IP-based remote devices using SSH and SCP using Ruby calls. Can anyone help me?
It's based on the SSH protocol used with it. A client can use an SCP to upload files to a remote server safely, download files, or even transfer files via SSH across remote servers.
The scp command uses SSH to transfer data, so it requires a password or passphrase for authentication. Unlike rcp or FTP, scp encrypts both the file and any passwords exchanged so that anyone snooping on the network cannot view them.
Secure copy protocol (SCP) is a means of securely transferring computer files between a local host and a remote host or between two remote hosts. It is based on the Secure Shell (SSH) protocol. "SCP" commonly refers to both the Secure Copy Protocol and the program itself.
Copy a Local File to a Remote System with the scp Command 0.2 is the server IP address. The /remote/directory is the path to the directory you want to copy the file to. If you don't specify a remote directory, the file will be copied to the remote user home directory.
example:
require 'net/scp'
host = '10.10.10.10'
login = 'foo'
password = 'bar'
Net::SCP.start(host, login, :password => password) do |scp|
puts 'SCP Started!'
scp.download('/usr/share/ruby.rb', '.')
end
there's also an scp.upload
The Net::SSH library includes Net::SCP, so you should start looking there.
From the Net::SCP docs:
require 'net/scp' # upload a file to a remote server Net::SCP.upload!("remote.host.com", "username", "/local/path", "/remote/path", :password => "password") # download a file from a remote server Net::SCP.download!("remote.host.com", "username", "/remote/path", "/local/path", :password => password) # download a file to an in-memory buffer data = Net::SCP::download!("remote.host.com", "username", "/remote/path")
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