Created
January 15, 2012 17:18
-
-
Save maliqq/1616495 to your computer and use it in GitHub Desktop.
multithread FTP upload
This file contains hidden or 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
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