Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FTP **TO** Rails app hosted on Heroku?

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?

like image 340
neezer Avatar asked Apr 04 '11 18:04

neezer


2 Answers

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:

  • Do not forget ftp.passive = true since Heroku does not support active mode.
  • Everything you want to do should be contained in the rake task since Heroku will erase the tmp directory once the task is over.
like image 69
jbescoyez Avatar answered Sep 20 '22 18:09

jbescoyez


Heroku does not support your application receiving FTP.

You could possibly write a Heroku addon around receiving FTP, if you really want it.

like image 31
yfeldblum Avatar answered Sep 21 '22 18:09

yfeldblum