Threading is light in ruby, so here a try show works in paralleles :

require 'thread'
require 'socket'
require 'timeout'

############### Send a file by socket to www server

def send_file(hostname,filename)
 timeout(3+File.size(filename)/10000) { # timeout, in seconds
   socket=TCPSocket.open(hostname,80)
   socket.write( "POST /upload/#{filename} HTTP/1.1\r\n\r\nContent=" )
   socket.write( IO.read(filename) )
   print "\n#{filename} transfered"
 }
rescue Exception => ex
 puts "ERROR on transfert #{filename} to {hostname} : #{ex}"
ensure
 socket.close rescue nil  # anyway, try to close
end

################### MAIN : send  *.rb in //

threads= Dir["*.rb"].map do |file|
  sleep(0.1) while Thread.list.size>20
  Thread.new { send_file(ARGV[0],file) }
end
threads.each {|thread| thread.join} # wait all finish before exit

Attachments:
http://www.ruby-forum.com/attachment/5114/beauty.rb

-- 
Posted via http://www.ruby-forum.com/.