Guest User

Untitled

a guest
Apr 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. require 'fileutils'
  4.  
  5. def main local, remote, to="/tmp/"
  6. to_file = get_remote(remote, to)
  7. rsize = File.size(to_file)
  8. lsize = File.size(local)
  9. if rsize > lsize
  10. FileUtils.cp(to_file, local)
  11. elsif rsize == lsize
  12. # do nothing.
  13. elsif rsize < lsize
  14. send_remote(local, remote)
  15. else
  16. raise "must not happen"
  17. end
  18. end
  19.  
  20. def get_remote remote, to
  21. to_file = File.join(to, remote.gsub(%r{/}, '_'))
  22. system("scp #{remote} #{to_file}")
  23. to_file
  24. end
  25.  
  26. def send_remote local, remote
  27. system("scp #{local} #{remote}")
  28. end
  29.  
  30. local = ARGV.shift
  31. remote = ARGV.shift
  32.  
  33. main(local, remote)
Add Comment
Please, Sign In to add comment