Does anyone know of a way to get a status update from ruby's Net::FTP library while downloading a file? I am trying to implement a web interface that shows a progress bar for percentage remaining when downloading a file from a remote ftp server.
For future reference - I stumbled upon a solution:
filesize = ftp.size(filename)
transferred = 0
p "Beginning download, file size: #{filesize}"
ftp.getbinaryfile(filename, "#{SOURCE_IMPORT_DIRECTORY}/#{filename}", 1024) { |data|
transferred += data.size
percent_finished = ((transferred).to_f/filesize.to_f)*100
p "#{percent_finished.round}% complete"
}
ftp.close
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With