Skip to content

Instantly share code, notes, and snippets.

@maliqq
Created January 15, 2012 17:18
Show Gist options
  • Save maliqq/1616495 to your computer and use it in GitHub Desktop.
Save maliqq/1616495 to your computer and use it in GitHub Desktop.
multithread FTP upload
require 'net/ftp'
threads = []
# creating threads
4.times { |i|
threads << Thread.new(i) {
while path = paths.shift
puts "uploading: #{path}"
ftp = Net::FTP.new("{host}")
ftp.passive = true; ftp.binary = true
ftp.login("{username}", "{password}")
ftp.chdir("/")
ftp.putbinaryfile(path) if File.exists?(path)
end
}
}
threads.each { |th| th.join }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment