FTP **TO** Heroku 上托管的 Rails 应用程序?

发布于 2024-10-30 01:29:53 字数 404 浏览 1 评论 0原文

请原谅这个奇怪的问题,但是有没有办法让我的 Rails 应用程序接收 FTP 传输?

我每天都有 FTP 上传,但我无法控制,每天都会将数百个 HTML 页面上传到我们现有的服务器。我想将此站点移至 Heroku 上的仅 Rails 部署,但我无法触及此 FTP 上传(这仍然需要发生)。

由于 Heroku 不提供公共存储空间或 FTP,因此我无法将文件直接上传到 Heroku(而且我真的不想这样做)。我想要的是将 FTP 上传指向我的 Rails 应用程序,然后让我的 Rails 应用程序接收并解析 HTML 文件以提取我需要的信息,将其存储在数据库中,并执行我需要执行的任何其他操作。 (有点像 RESTful 操作,但通过 FTP 而不是任何标准 REST 动词)。

这有可能吗,还是我因为这样想而发疯?如果可能的话,我将如何去做呢?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

尛丟丟 2024-11-06 01:29:54

我还需要一个 Heroku 实例来通过 FTP 接收文件。

我正在考虑使用 Brick FTP

webhook 发出文件已上传信号时,我计划下载文件内容并将其导入数据库。

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.

小梨窩很甜 2024-11-06 01:29:54

FTP 不支持主机标头,因此您将很难将请求发送到 Heroku 网格和我想象的应用程序。

我更倾向于将您的文件发送到 Amazon S3 存储桶,并让您的应用程序从那里获取文件并以这种方式处理它们,或者类似地让您的应用程序访问 FTP 服务器并检索文件以这种方式进行处理。

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.

故事未完 2024-11-06 01:29:54

是的,这应该是可能的。您需要研究 net/ftp 模块并检查其工作原理,但这应该是可能的。

我发现这个项目可能可以作为一个例子。

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.

没有心的人 2024-11-06 01:29:53

您可以使用 cron 安排 rake 任务,该任务将检索 ftp 服务器上的文件并将它们上传到您的数据库中。

您的 cron.rake 文件应如下所示:

    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

请记住两件事:

  • 不要忘记 ftp.passive = true ,因为 Heroku 不支持主动模式。
  • 你想做的所有事情都应该包含在 rake 任务中,因为一旦任务结束,Heroku 就会删除 tmp 目录。

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.
蓝海似她心 2024-11-06 01:29:53

Heroku 不支持您的应用程序接收 FTP。

如果您确实想要的话,您可以围绕接收 FTP 编写一个 Heroku 插件。

Heroku does not support your application receiving FTP.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文