I have a process that fetches a flat file from a mainframe via FTP. This usually works fine, but every now and then the file will contain something an accent character. If I try to get a file containing an accent, the entire process fails with the following error: Encoding::UndefinedConversionError: "\x88" from ASCII-8BIT to UTF-8
That's using Net::FTP's gettextfile method. Many people suggest simply switching to getbinaryfile - doing so will allow me to download the file, but it the resulting file is something that I can no longer parse (says it's in UTF-8, but the contents make no sense).
Is there any way to simply fetch and save the file as ASCII without having rails automatically convert the output to UTF-8? Here's my code:
Net::FTP.open(config['host']) do |ftp|
Rails.logger.info("FTP Connection established")
ftp.login(config['user'], config['password'])
Rails.logger.info("Login Successful")
ftp.gettextfile("'#{config['es_in']}'", "data/es-in.#{Time.now.utc.strftime("%Y%m%d-%H%M%S")}")
ftp.gettextfile("'#{config['ca_in']}'", "data/ca-in.#{Time.now.utc.strftime("%Y%m%d-%H%M%S")}")
Rails.logger.info("Download(s) completed, terminating connection.")
end