c*****m 发帖数: 1160 | 1 【 以下文字转载自 Linux 讨论区 】
发信人: chatham (聊天火腿), 信区: Linux
标 题: 在服务器端如何确认一个文件已经ftp传输完毕?
发信站: BBS 未名空间站 (Fri Mar 14 12:01:49 2014, 美东)
我需要在服务器上监测一个ftp目录,客户上传文件之后,这里把文件拷贝(mv)到
backup目录然后解压分析处理。
我总能用列文件的方式对在这个目录出现的文件处理,但是我怎么能知道这个文件是“
正在传输中”还是“已经完成传输”?
我所能想到的方法就是用file modified time跟当前 server clock比较,如果已经超
过1分钟(或者更长时间,5分钟?)就认为完成传输。
有什么建议?谢谢。
Ubuntu 12.04服务器。 |
b******6 发帖数: 572 | 2 只是一个想法
查看文件 node 是不是有别的打开,如果有,是不是 ftp
看看 lsof 命令能不能帮忙。
【在 c*****m 的大作中提到】 : 【 以下文字转载自 Linux 讨论区 】 : 发信人: chatham (聊天火腿), 信区: Linux : 标 题: 在服务器端如何确认一个文件已经ftp传输完毕? : 发信站: BBS 未名空间站 (Fri Mar 14 12:01:49 2014, 美东) : 我需要在服务器上监测一个ftp目录,客户上传文件之后,这里把文件拷贝(mv)到 : backup目录然后解压分析处理。 : 我总能用列文件的方式对在这个目录出现的文件处理,但是我怎么能知道这个文件是“ : 正在传输中”还是“已经完成传输”? : 我所能想到的方法就是用file modified time跟当前 server clock比较,如果已经超 : 过1分钟(或者更长时间,5分钟?)就认为完成传输。
|
n*****t 发帖数: 22014 | 3 先 ftp to ./tmp,然后 mv to ./upload,假设你是用 web 做 upload
【在 c*****m 的大作中提到】 : 【 以下文字转载自 Linux 讨论区 】 : 发信人: chatham (聊天火腿), 信区: Linux : 标 题: 在服务器端如何确认一个文件已经ftp传输完毕? : 发信站: BBS 未名空间站 (Fri Mar 14 12:01:49 2014, 美东) : 我需要在服务器上监测一个ftp目录,客户上传文件之后,这里把文件拷贝(mv)到 : backup目录然后解压分析处理。 : 我总能用列文件的方式对在这个目录出现的文件处理,但是我怎么能知道这个文件是“ : 正在传输中”还是“已经完成传输”? : 我所能想到的方法就是用file modified time跟当前 server clock比较,如果已经超 : 过1分钟(或者更长时间,5分钟?)就认为完成传输。
|
c*****m 发帖数: 1160 | 4
客户是用普通ftp软件上传,我这里就是要判断何时上传完毕,再mv.
查 node的方式听起来不错,我查一些资料看,谢了。
【在 n*****t 的大作中提到】 : 先 ftp to ./tmp,然后 mv to ./upload,假设你是用 web 做 upload
|
l*********s 发帖数: 5409 | 5 look at your ftp server's log, they will contain the information. |
k********e 发帖数: 702 | 6 ftp 支持断点续传,这个方法并不靠谱。
还有,就算关闭文件了,怎么验证文件完整性?怎么知道不是网络断了?
【在 b******6 的大作中提到】 : 只是一个想法 : 查看文件 node 是不是有别的打开,如果有,是不是 ftp : 看看 lsof 命令能不能帮忙。
|
m******t 发帖数: 635 | 7 http://www.perlmonks.org/?node_id=582713
两个方案:
1. 设置ftp server,上传完成后自动转存到指定目录 (inotify或者cronjob这里应该
都可以)
2. 定义parse ftp server的log,找完成标识
【在 c*****m 的大作中提到】 : : 客户是用普通ftp软件上传,我这里就是要判断何时上传完毕,再mv. : 查 node的方式听起来不错,我查一些资料看,谢了。
|
n*****t 发帖数: 22014 | 8 pureftpd calluploadscript=yes
【在 c*****m 的大作中提到】 : : 客户是用普通ftp软件上传,我这里就是要判断何时上传完毕,再mv. : 查 node的方式听起来不错,我查一些资料看,谢了。
|
c*****m 发帖数: 1160 | 9 文件会是zip文件。也许我可以用zip来检查它是否完整? |
c*****m 发帖数: 1160 | 10
谢了。看起来还是很古老的问题呢,8年了。
【在 m******t 的大作中提到】 : http://www.perlmonks.org/?node_id=582713 : 两个方案: : 1. 设置ftp server,上传完成后自动转存到指定目录 (inotify或者cronjob这里应该 : 都可以) : 2. 定义parse ftp server的log,找完成标识
|
|
|
c*****m 发帖数: 1160 | 11 最后还是用验证zip file的方式来做了。因为我所拿到的都是 zip file,如果最后部
分没有上传上来的话,unzip -v 会说:
unzip -v a1.zip
Archive: a1.zip
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of a1.zip or
a1.zip.zip, and cannot find a1.zip.ZIP, period.
(exit code=9)
而用python的 zipfile.is_zipfile(filelocation) 就会得到 false.
所以我用这个就足够判断了。
谢谢大家的讨论。 |
m******t 发帖数: 635 | 12 上传是zip的话就容易不少,:)
【在 c*****m 的大作中提到】 : 最后还是用验证zip file的方式来做了。因为我所拿到的都是 zip file,如果最后部 : 分没有上传上来的话,unzip -v 会说: : unzip -v a1.zip : Archive: a1.zip : End-of-central-directory signature not found. Either this file is not : a zipfile, or it constitutes one disk of a multi-part archive. In the : latter case the central directory and zipfile comment will be found on : the last disk(s) of this archive. : unzip: cannot find zipfile directory in one of a1.zip or : a1.zip.zip, and cannot find a1.zip.ZIP, period.
|
n*****t 发帖数: 22014 | 13 Calluploadscript 更省事吧,天生为你这个问题设计的
【在 c*****m 的大作中提到】 : 最后还是用验证zip file的方式来做了。因为我所拿到的都是 zip file,如果最后部 : 分没有上传上来的话,unzip -v 会说: : unzip -v a1.zip : Archive: a1.zip : End-of-central-directory signature not found. Either this file is not : a zipfile, or it constitutes one disk of a multi-part archive. In the : latter case the central directory and zipfile comment will be found on : the last disk(s) of this archive. : unzip: cannot find zipfile directory in one of a1.zip or : a1.zip.zip, and cannot find a1.zip.ZIP, period.
|
c*****m 发帖数: 1160 | 14
这难道不是“pureftpd”的专门设置?我都不肯定我现在这个是哪个 ftpd.
【在 n*****t 的大作中提到】 : Calluploadscript 更省事吧,天生为你这个问题设计的
|
c****3 发帖数: 10787 | 15 FTP协议是控制和数据两个不同TCP连接,用正常关闭数据连接,来表示文件传输完毕。
协议是这么设计的,TCP连接不是通过正常方式关闭,都算文件传输不完整,这只有服
务器知道,没有其他办法。
但有的服务器端有选项,能自动删除上传不完整的文件,找找你的服务器又没有这个选
项。 |