Created
July 27, 2009 08:53
-
-
Save jolts/156114 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
abort 'nu-uh' if ARGV.empty? | |
%w[net/ftp rubygems progressbar highline/import].each {|l| require l} | |
conf = { | |
:host => 'localhost', | |
:user => 'jolts', | |
:pass => 'test', | |
:rdir => '.' | |
} | |
ftp = Net::FTP.new conf[:host] | |
ftp.login conf[:user], conf[:pass] | |
dir = ask 'Remote directory: ' do |q| | |
q.default = conf[:rdir] | |
end | |
ftp.chdir dir | |
puts ["\n"] << ftp.dir << ["\n"] | |
ARGV.each do |file| | |
pbar = ProgressBar.new File.basename(file), 100 | |
filesize, completedsize, oldpercent = File.size(file).to_f, 0, 0 | |
ftp.put file, File.basename(file) do |data| | |
completedsize += data.size | |
percent = (completedsize / filesize) * 100 | |
increment = percent - oldpercent | |
pbar.inc increment | |
oldpercent = percent | |
end | |
pbar.finish | |
end | |
ftp.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment