Grails 处理 FTP 转储
我有一个网站,用户可以使用表单上传文件,并且可以发布内容,这非常棒,但一位客户坚持使用 FTP。我已经确定了处理此问题的三个选项,我想知道是否有人对哪个最好有任何见解(或者如果存在不同的溢出,我应该询问这个问题),或者是否有第四个更好的选项。
解决方案1:学习Linux。我可能可以编写一个 cron 作业,每隔 5 分钟查看一次他们上传的目录,然后将找到的文件发布到我的网站中。
解决方案 2:在 grails 中创建一个计时器驱动的服务,每 5 分钟检查一次目录。这就是我要开始尝试的。
解决方案 3:这会很难,但我确信让 grails 假装成 FTP 服务器,允许 ftp 转储就像一个帖子一样可能。我不知道从哪里开始这个解决方案,所以除非有插件,否则这种情况不会发生。
I have a site where users are uploading files with a form and it posts and its great, but one customer insists on using FTP instead. I have determined three options for handling this, and I was wondering if anyone has any insight on which is best (or if there is a different overflow I should be asking this on), or if there is a fourth better option.
Solution 1: Learn Linux. I could probably write a cron job that looks in the directory to which they're uploading every 5 minutes and then post the files it finds into my site.
Solution 2: Create a timer driven service in grails that looks in the directory every 5 minutes. This is what I'm going to start trying.
Solution 3: This would be hard, but I'm sure it would be possible to have grails pretend to be a FTP server allowing the ftp dump to be like a post. I have no idea where to start this solution, so unless there is a plugin this isn't happening.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想采用选项二,您可以使用 Grails Quartz 插件 来安排任务在你的清单中。
You can use the Grails Quartz plug-in to schedule a task, if you want to pursue option two in your list.
我会选择选项 2 并按照建议使用 Quartz 插件(而不是 cron)。在 Groovy 中处理文件很简单,并且有很多示例,例如 此来自 mrhaki。
如果您认为文件处理会有更复杂的要求,您可以尝试使用 Apache Camel 之类的 这个 示例来自同一个 mrhaki。尽管我相信 Spring 有它自己的框架,可能更适合,但如果您走这条路,您将必须自己进行调查。
I would go for option 2 and use the Quartz plugin as suggested (rather than cron). Handling files in Groovy are simple and you have lots of examples such as this from mrhaki.
If you think the processing of files will have more complex requirements you could try out something like Apache Camel with this example from the same mrhaki. Though I believe Spring has its own framework that may be a better fit, you'll have to investigate that yourself if you go down that road.
Grails 是一个 Web 框架,因此选项 2 和 3 不太理想。如果在您的应用程序中立即提供 fted 的文件,我认为选项 1 是 3 种解决方案中最快、最简单的解决方案。
另一种选择是找到一个开源 FTP 服务器(有多个)并修改它以将文档直接导入到您的系统中。这将允许您的客户使用他们喜欢的协议 (FTP),并且仍然将文件实时获取到您的应用程序中。
还有一个选择是提供一个类似 FTP 的客户端,它将使用您的 grails 应用程序作为服务器。这是否合适取决于客户坚持使用 FTP 的原因,您应该提前确定这一点,以确保您的解决方案适合他们。
Grails is a web framework so options 2 and 3 are less than ideal. If having the file that is ftped immediately available in your application option 1 is the quickest and simplest solution of the 3 I think.
Another option is to find an open source FTP server (there are several) and modify it to import the document into your system directly. This will allow your client to use the protocol they prefer (FTP) and still get the file into your application in real time.
Still another option is to provide an FTP like client that will use your grails application as the server. Whether this is suitable or not depends on why the client insists on using FTP which you should determine up front to make sure your solution works for them.