Created
February 21, 2009 16:56
-
-
Save noplans/68092 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vim: fileencoding=utf-8 | |
require 'rubygems' | |
require 'net/ssh' | |
require 'net/scp' | |
require 'pit' | |
host = 'ruby-sapporo.org' | |
conf = Pit.get(host, :require => {"username" => "username", "password" => "password"}) | |
files = ['cs.rdf', 'file1', 'file2'] | |
dest_dir = "/var/www/torisetsu/feeds" | |
Net::SSH.start(host, conf['username']) do |ssh| | |
# upload files to home directory on remote host | |
files.each{|f| ssh.scp.upload!(f, "~/", :preserve => true) } | |
puts "files have been copied." | |
prompt = "password:" | |
cmd = "sudo -p '#{prompt}' mv #{files.join(" ")} #{dest_dir}" | |
ssh.open_channel do |ch| | |
ch.exec(cmd) do |ch, success| | |
raise 'Error' unless success | |
ch.on_extended_data do |ch, type, data| | |
ch.send_data("#{conf["password"]}\n") if data =~ /#{prompt}/ | |
end | |
end | |
end | |
ssh.loop | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment