验证ftp是否完整? [英] Verify whether ftp is complete or not?

查看:171
本文介绍了验证ftp是否完整?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序连续轮询文件夹。一旦任何文件是ftp的文件夹,应用程序必须将此文件移动到其他文件夹进行处理。



在这里,我们没有任何选项来验证ftp是否完整。

在技术论坛中建议使用一个命令lsof。它有一个文件描述列,它给出了文件状态。



因为这是一个免费的bsd命令,并且不存在于老版本的linux中,我想澄清一下用法



您可以告诉我们您在文件验证方面的经验吗?是否还有其他可用的解决方案?



另外,使用这个工具有没有什么风险?

提前感谢您的帮助。

谢谢,
Mathew Liju

解决方案

我们之前以许多不同的方式完成了这项工作。



方法一:



如果您可以控制发送文件的进程,文件本身后跟一个哨兵文件。例如,发送真实文件contracts.doc,后跟一个字节contracts.doc.sentinel

然后让你的监听器进程监视哨兵文件。当它们中的一个被创建时,您应该处理等效数据文件,然后删除它们。



任何超过一天的数据文件都没有相应的数据文件方法二:



注意文件本身(特别是上次修改日期/时间)。只处理过去修改时间大于 N 分钟的文件。这会增加处理文件的延迟时间,但通常可以肯定的是,如果文件在五分钟内没有被写入(例如),就完成了。



结论:



过去这两种方法都已成功应用。我更喜欢第一个,但是当我们不允许更改发送文件的过程时,我们必须使用第二个。



第一个的优点是您知道文件在出现哨兵文件时就绪。既然 lsof (我假设你将任何进程打不开的文件视为可以处理的文件)和时间戳,那么FTP可能会崩溃中间,你可能正在处理一半的文件。


I got an application which is polling on a folder continuously. Once any file is ftp to the folder, the application has to move this file to some other folder for processing.

Here, we don't have any option to verify whether ftp is complete or not.

One command "lsof" is suggested in the technical forums. It got a file description column which gives the file status.

Since, this is a free bsd command and not present in old versions of linux, I want to clarify the usage of this command.

Can you guys tell us your experience in file verification and is there any other alternative solution available?

Also, is there any risk in using this utility?

Appreciate your help in advance.

Thanks, Mathew Liju

解决方案

We've done this before in a number of different ways.

Method one:

If you can control the process sending the files, have it send the file itself followed by a sentinel file. For example, send the real file "contracts.doc" followed by a one-byte "contracts.doc.sentinel".

Then have your listener process watch out for the sentinel files. When one of them is created, you should process the equivalent data file, then delete both.

Any data file that's more than a day old and doesn't have a corresponding sentinel file, get rid of it - it was a failed transmission.

Method two:

Keep an eye on the files themselves (specifically the last modification date/time). Only process files whose modification time is more than N minutes in the past. That increases the latency of processing the files but you can usually be certain that, if a file hasn't been written to in five minutes (for example), it's done.

Conclusion:

Both those methods have been used by us successfully in the past. I prefer the first but we had to use the second one once when we were not allowed to change the process sending the files.

The advantage of the first one is that you know the file is ready when the sentinel file appears. With both lsof (I'm assuming you're treating files that aren't open by any process as ready for processing) and the timestamps, it's possible that the FTP crashed in the middle and you may be processing half a file.

这篇关于验证ftp是否完整?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆