Guest User

Untitled

a guest
Apr 13th, 2018
642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. abort 'nu-uh' if ARGV.empty?
  3.  
  4. %w[net/ftp rubygems progressbar highline/import].each {|l| require l}
  5.  
  6. conf = {
  7. :host => 'localhost',
  8. :user => 'jolts',
  9. :pass => 'test',
  10. :rdir => '.'
  11. }
  12.  
  13. ftp = Net::FTP.new conf[:host]
  14. ftp.login conf[:user], conf[:pass]
  15.  
  16. dir = ask 'Remote directory: ' do |q|
  17. q.default = conf[:rdir]
  18. end
  19.  
  20. ftp.chdir dir
  21.  
  22. puts ["\n"] << ftp.dir << ["\n"]
  23.  
  24. ARGV.each do |file|
  25. pbar = ProgressBar.new File.basename(file), 100
  26. filesize, completedsize, oldpercent = File.size(file).to_f, 0, 0
  27.  
  28. ftp.put file, File.basename(file) do |data|
  29. completedsize += data.size
  30. percent = (completedsize / filesize) * 100
  31. increment = percent - oldpercent
  32.  
  33. pbar.inc increment
  34.  
  35. oldpercent = percent
  36. end
  37.  
  38. pbar.finish
  39. end
  40.  
  41. ftp.close
Add Comment
Please, Sign In to add comment