How to set FTP server idle timeout in Ruby?

I have a Ruby thread that first connects to an FTP server and then uploads thousands of files. Due to some connectivity issues, the Ruby thread often freezes. Therefore, I want to set a timeout for idle ftp.

A post by Ruby Net :: FTP Timeout Threads suggests using the Timeout module:

begin Timeout.timeout(10) do // connect to FTP and upload end rescue Timeout::Error ... end 

This approach will not solve my problem, because the timeout is for the entire block of calculations, not the timeout, starting with the inactivity and inactivity of the FTP session.

So what should I do?

+4
source share
1 answer

Try something like this

 transferred = 0 buffersize = 1024 filesize = File.size(file) ftp.putbinaryfile(file, "/private/transfer/#{File.basename(file)}", buffersize) { |data| raise "no data sent" if data.size == 0 or data.size < buffersize } 
0
source

Source: https://habr.com/ru/post/1384233/


All Articles