如何检测文件是否通过FTP上传 [英] How to detect that a file is being uploaded over FTP

查看:425
本文介绍了如何检测文件是否通过FTP上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序正在关注用户可以上传文件的一组文件夹。当一个文件上传完成后,我必须申请一个处理,但我不知道如何检测到一个文件没有完成上传。



任何方式来检测如果一个文件还没有被FTP服务器释放?

解决方案

这个问题没有通用的解决方案。 b
$ b

某些FTP服务器会锁定正在上传的文件,导致您无法访问文件,而文件仍在上传。例如IIS FTP服务器就是这样做的。大多数其他FTP服务器不。在防止文件被上传时查看我的答案。



这个问题有一些常见的解决方法(最初发布在 SFTP文件锁定机制中,但也与FTP相关):


  • 上传完成后,客户端可以上传完成文件。使您的自动系统等待完成文件出现。
  • 您可以有一个专门的上传文件夹,让客户端(原子)将上传的文件移动到完成夹。使您的自动系统只能查看完成文件夹。
  • 为上传的文件(.filepart)设置文件命名约定,并让客户端(原子级地)重命名文件上传到它的最终名称。让您的自动系统忽略.filepart文件。

    请参阅(我的)文章


    一些FTP服务器允许你在上传/上传到临时文件名时锁定文件当上传完成时配置一个被调用的钩子。你可以利用这个。例如,ProFTPD有一个 mod_exec模块(请参阅 ExecOnCommand 指令)。


    My application is keeping watch on a set of folders where users can upload files. When a file upload is finished I have to apply a treatment, but I don't know how to detect that a file has not finish to upload.

    Any way to detect if a file is not released yet by the FTP server?

    解决方案

    There's no generic solution to this problem.

    Some FTP servers lock the file being uploaded, preventing you from accessing it, while the file is still being uploaded. For example IIS FTP server does that. Most other FTP servers do not. See my answer at Prevent file from being accessed as it's being uploaded.

    There are some common workarounds to the problem (originally posted in SFTP file lock mechanism, but relevant for the FTP too):

    • You can have the client upload a "done" file once the upload finishes. Make your automated system wait for the "done" file to appear.
    • You can have a dedicated "upload" folder and have the client (atomically) move the uploaded file to a "done" folder. Make your automated system look to the "done" folder only.
    • Have a file naming convention for files being uploaded (".filepart") and have the client (atomically) rename the file after upload to its final name. Make your automated system ignore the ".filepart" files.
      See (my) article Locking files while uploading / Upload to temporary file name for an example of implementing this approach.

    Some FTP servers allow you to configure a hook to be called, when an upload is finished. You can make use of that. For example ProFTPD has a mod_exec module (see the ExecOnCommand directive).

    这篇关于如何检测文件是否通过FTP上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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