Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sudo yum install rubygems
- sudo gem install net-ssh net-sftp highline echoe
- #!/usr/bin/env ruby
- require 'rubygems'
- require 'net/ssh'
- require 'net/sftp'
- require 'highline/import'
- file = ARGV[ 0 ] # filename from command line
- prod = file + "-new" # product filename (call it <file>-new)
- rpath = "/tmp" # remote computer operating directory
- rfile = "#{rpath}/#{file}" # remote filename
- rprod = "#{rpath}/#{prod}" # remote product
- cmd = "mv #{rfile} #{rprod}" # remote command, constructed
- host = "-YOUR REMOTE HOST-"
- user = "-YOUR REMOTE USERNAME-"
- pass = ask("Password: ") { |q| q.echo = false } # password from stdin
- Net::SSH.start(host, user, :password => pass) do |ssh|
- ssh.sftp.connect do |sftp|
- # upload local 'file' to remote 'rfile'
- sftp.upload!(file, rfile)
- # run remote command 'cmd' to produce 'rprod'
- ssh.exec!(cmd)
- # download remote 'rprod' to local 'prod'
- sftp.download!(rprod, prod)
- end
- end
- dylan@home ~/tmp/ruby) ls
- bar remotefoo.rb*
- dylan@home ~/tmp/ruby) ./remotefoo.rb bar
- Password:
- dylan@home ~/tmp/ruby) ls
- bar bar-new remotefoo.rb*
Add Comment
Please, Sign In to add comment