How to give a timeout to an FTP connection

Posted by dierre on Stack Overflow See other posts from Stack Overflow or by dierre
Published on 2012-06-11T22:36:31Z Indexed on 2012/06/11 22:40 UTC
Read the original article Hit count: 250

Filed under:
|

The story behind:

Old script written in ruby 1.8.6 that opens a connection to a ftp and download a configuration file. For a specific client with a windows ftp server the script just hangs. The log stops writing after it opens the connection to the ftp. It's an old script, it's in ruby and I'm not an expert on it.

What I tried:

So I tried this implementation of a timeout to check if an ftp connection hangs out with this code

Timeout::timeout(5) {
ftp = Net::FTP.new(host,pass,host)
}

The problem is that this isn't working. My guess is that the interpreter stops on opening the connection and the timeout doesn't kill the connection because the interpreter is stuck.

Is it possible that that's the problem?

Could you tell me if there is maybe an alternative solution or if I'm doing something wrong?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about ftp