Reputation: 31
Ive seen similar questions asked before but none that are as basic as mine. I know that it is possible to do using Net::FTP
and threads. My question is how do you create a thread and pass it a file to upload. Im still very new to the concept of threads.
Upvotes: 2
Views: 184
Reputation: 34328
For OSX you could also look into Automator with Upload to FTP.
However with Ruby something like this could be used as a starting point:
def ftp_send_file(file)
Net::FTP.open("hostname") do |ftp|
ftp.login("user", "password")
...
ftp.putbinaryfile(file)
end
end
8.times { |i|
puts "Starting upload no. #{i}..."
# Launch a new thread for file upload
Thread.new { ftp_send_file("the_big_file_#{i}") }
}
# Main thread waits for all upload threads to finish
(Thread.list - [Thread.current]).each(&:join)
As you can see it's really not that complicated to start a thread. Just read the Thread
docs. Many more examples in there.
Upvotes: 1