require 'rubygems' |
02 | require 'net/ssh' |
03 | |
04 | def copy_file(session, source_path, destination_path= nil ) |
05 | destination_path ||= source_path |
06 | cmd = %{cat > "#{destination_path.gsub('" ', '\"' )}"} |
07 | session.process.popen3(cmd) do |i, o, e| |
08 | puts "Copying #{source_path} to #{destination_path}... " |
09 | open(source_path) { |f| i.write(f.read) } |
10 | puts 'Done.' |
11 | end |
12 | end |
13 | |
14 | Net:: SSH .start( 'example.com' , :username => 'yourName' , |
15 | :password => 'mypass' ) do |session| |
16 | copy_file(session, '/home/test.rb' ) |
17 | end |