如何检测FTP文件传输完成? [英] How to detect FTP file transfer completion?

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

问题描述

我正在编写一个脚本,用于轮询FTP站点的文件并在本地可用时下载它们。这些文件被各方随机存入FTP站点。我需要一种方法来检测FTP站点上的文件是否已完全由源端传输,然后再下载它们。关于如何去做这件事的任何想法?

I am writing a script that polls an FTP site for files and downloads them locally as and when available. The files are deposited to the FTP site randomly by various source parties. I need a way to be able to detect if the file on the FTP site has been transferred over completely by the source party, before downloading them. Any thoughts on how to go about this?

感谢您提供任何帮助!

推荐答案

如果你无法操作FTP服务器本身,检查的唯一方法就是查询文件大小,如果文件大小不会长时间更改,则可以确定上传已完成。但没有人能保证。理想情况下,您可以修改FTP服务器并在完成一些上传后执行一些脚本。

If you cannot manipulate the FTP server itself the only way of checking that comes to my mind is polling the filesize and if the filesize doesn't change for a longer time you can be quite sure the upload has finished. But nobody can guarantee. Ideally you can adapt the FTP server and make it execute some script after finishing some upload.

一些伪代码:

my %filesizes;
my %processed;

sub poll {
    foreach (@files_on_ftp) {
         if($_->filesize == $filesizes{$_->filename} and not $processed{$_->filename}) {
             process($_);
             $processed{$_->filename)++;
         }
    }
}

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

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