Pardon the whacky question, but is there anyway to have my Rails app receive a FTP transmission?
I have daily FTP upload that I have no control over, which uploads several hundred HTML pages to our existing server each day. I want to move this site to a Rails-only deployment on Heroku, but I can't touch this FTP upload (which still needs to happen).
Since Heroku doesn't offer public storage space or FTP, I can't upload the files directly to Heroku (and I don't really want to). What I would love is to point the FTP upload to my Rails app, and have my Rails app receive and parse the HTML files to pull out the information I need, store it in the database, and do whatever else I need to do with it. (Kinda like a RESTful action, but via FTP instead of any of the standard REST verbs).
Is this at all possible or am I barking mad for thinking it? If it is possible, how would I go about doing this?
You can schedule a rake task with cron which will retrieve files on the ftp server and upload them in your db.
Here is how your cron.rake file should look like:
require 'net/ftp'
task :cron => :environment do
Dir.chdir("tmp") do
Net::FTP.open("ftp.example.com") do |ftp|
ftp.passive = true
ftp.login('login', 'password')
ftp.chdir("your_dir")
ftp.get("your_file")
# ... Load the files in the database here
end
end
end
Two things to keep in mind:
ftp.passive = true
since Heroku does not support active mode.Heroku does not support your application receiving FTP.
You could possibly write a Heroku addon around receiving FTP, if you really want it.
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