I already get records from a ftp server with the gettextfile method and work on each record in the given block to finally put it elsewhere.
This file is a CSV file and I need to proceed it with CSV to get headers and datas and put it on DB after some work. As I have many different files, I need a generic way. I don't want to load all records on memory or disk, because the files can be very big! So a stream would be good
One idea is to give a io object to the CSV, but I don't see how to do that with Net::FTP.
I already see "http://stackoverflow.com/questions/5223763/how-to-ftp-in-ruby-without-first-saving-the-text-file" but it work with PUT.
Any help?
The technique that Justin mentions creates a temporary file.
You could use retrlines:
filedata = ''
ftp.retrlines("RETR " + filename) do |block|
filedata << block
end
or retrbinary instead:
filedata = ''
ftp.retrbinary("RETR " + filename, Net::FTP::DEFAULT_BLOCKSIZE) do |block|
filedata << block
end
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