Guest User

Untitled

a guest
Jun 16th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. sudo yum install rubygems
  2. sudo gem install net-ssh net-sftp highline echoe
  3.  
  4. #!/usr/bin/env ruby
  5.  
  6. require 'rubygems'
  7. require 'net/ssh'
  8. require 'net/sftp'
  9. require 'highline/import'
  10.  
  11. file = ARGV[ 0 ] # filename from command line
  12. prod = file + "-new" # product filename (call it <file>-new)
  13. rpath = "/tmp" # remote computer operating directory
  14. rfile = "#{rpath}/#{file}" # remote filename
  15. rprod = "#{rpath}/#{prod}" # remote product
  16. cmd = "mv #{rfile} #{rprod}" # remote command, constructed
  17.  
  18. host = "-YOUR REMOTE HOST-"
  19. user = "-YOUR REMOTE USERNAME-"
  20. pass = ask("Password: ") { |q| q.echo = false } # password from stdin
  21.  
  22. Net::SSH.start(host, user, :password => pass) do |ssh|
  23. ssh.sftp.connect do |sftp|
  24. # upload local 'file' to remote 'rfile'
  25. sftp.upload!(file, rfile)
  26.  
  27. # run remote command 'cmd' to produce 'rprod'
  28. ssh.exec!(cmd)
  29.  
  30. # download remote 'rprod' to local 'prod'
  31. sftp.download!(rprod, prod)
  32. end
  33. end
  34.  
  35. dylan@home ~/tmp/ruby) ls
  36. bar remotefoo.rb*
  37. dylan@home ~/tmp/ruby) ./remotefoo.rb bar
  38. Password:
  39. dylan@home ~/tmp/ruby) ls
  40. bar bar-new remotefoo.rb*
Add Comment
Please, Sign In to add comment