开发者

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 He开发者_如何学JAVAroku (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:

  • 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.


Heroku does not support your application receiving FTP.

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


I also need a Heroku instance to receive files via FTP.

I am considering using Brick FTP.

When a webhook signals that a file has been uploaded I plan to download and import the file contents into the database.


FTP does not support host headers so you'll struggle getting your request into the Heroku grid and to your application I would imagine.

I would be more inclined to get your files to an Amazon S3 bucket and have your application get the files from there and process them that way, or similarly have your application reach out to the FTP server and retrieve the files for processing that way.


Yep this should be possible. You'll need to look into the net/ftp module and check out how that works but it should be possible.

I've found this project that could probably serve as an example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜