You can create another thread to watch the downloading progress and crash the application if the download appears unresponsive. Since Net::SFTP allows you to pass in a custom handler to the download!
method, you can set up the watcher thread like this:
class CustomHandler
def extend_time
@crash_time = Time.now + 30
end
# called when downloading has started
def on_open(downloader, file)
extend_time
downloader_thread = Thread.current
@watcher_thread = Thread.new{
while true do
if Time.now > @crash_time
downloader_thread.raise "Downloading appears unresponsive. Network disconnected?"
end
sleep 5
end
}
end
# called when new bytes are downloaded
def on_get(downloader, file, offset, data)
extend_time
end
# called when downloading is completed
def on_close(downloader, file)
@watcher_thread.exit
end
end
And don't forget to pass in the custom handler like this:
sftp.download!(remote_path, local_path, :progress => CustomHandler.new)