Skip to content

Instantly share code, notes, and snippets.

@jolts
Created July 27, 2009 08:53
Show Gist options
  • Save jolts/156114 to your computer and use it in GitHub Desktop.
Save jolts/156114 to your computer and use it in GitHub Desktop.
#!/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