Proftpd 验证上传完成
我想知道是否有最佳实践来检查上传到 ftp 服务器是否成功。
我正在使用的系统有一个上传目录,其中包含上传文件的每个用户的子目录。
这些目录中的文件只是临时的,一旦处理就会被丢弃。
系统循环遍历每个子目录和其中的新文件,并检查每个文件是否已修改 10 秒。如果10秒内没有修改,系统认为文件上传成功。
我不喜欢系统当前处理这些情况的方式,因为如果文件上传不完整,它将尝试处理文件并失败,而不是等待并允许用户恢复上传直到完成。 对于不需要很长时间上传的小文件来说可能没问题,但如果文件很大,我希望能够恢复上传。
我也不喜欢目录和文件的循环,系统在高CPU使用率下空闲,所以我实现了 pyinotify 在写入文件时触发操作。我还没有真正看过源代码,我只能假设它比当前的实现更优化(它的功能比我描述的要多)。
但我仍然需要检查文件是否已成功上传。
我知道我可以解析 xferlog 以获取所有完整的上传。就像:
awk '($12 ~ /^i$/ && $NF ~ /^c$/){print $9}' /var/log/proftpd/xferlog
这将使 pyinotify 变得不必要,因为如果我只跟踪日志,我可以获得完整和不完整上传的路径。
所以我的解决方案是检查运行循环中的 xferlog 并仅处理完整的文件。
除非有最佳实践或更好的方法来做到这一点?
这种方法有什么缺点?
我在 debian 服务器上运行我的应用程序,并且 proftpd 安装在同一服务器上。另外,我无法控制客户端发送文件。
I was wondering whether there was a best practice for checking if an upload to your ftp server was successful.
The system I'm working with has an upload directory which contains subdirectories for every user where the files are uploaded.
Files in these directories are only temporary, they're disposed of once handled.
The system loops through each of these subdirectories and new files in them and for each file checks whether it's been modified for 10 seconds. If it hasn't been modified for 10 seconds the system assumed the file was uploaded successfully.
I don't like the way the system currently handles these situations, because it will try and handle the file and fail if the file upload was incomplete, instead of waiting and allowing the user to resume the upload until it's complete.
It might be fine for small files which doesn't take a lot of time to upload, but if the file is big I'd like to be able to resume the upload.
I also don't like the loops of directories and files, the system idles at a high cpu usage, so I've implemented pyinotify to trigger an action when a file is written. I haven't really looked at the source code, I can only assume it is more optimized than the current implementation (which does more than I've described).
However I still need to check whether the file was successfully uploaded.
I know I can parse the xferlog to get all complete uploads. Like:
awk '($12 ~ /^i$/ && $NF ~ /^c$/){print $9}' /var/log/proftpd/xferlog
This would make pyinotify unnecessary since I can get the path for complete and incomplete uploads if I only tail the log.
So my solution would be to check the xferlog in my run-loop and only handle complete files.
Unless there's a best practice or simply a better way to do this?
What would the disadvantages be with this method?
I run my app on a debian server and proftpd is installed on the same server. Also, I have no control over clients sending the file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 proftpd 文档,我看到 http://www.proftpd.org/docs /directives/linked/config_ref_HiddenStores.html
当您控制 proftpd 时,这应该是解决问题的“更好方法”,因为它会为您处理所有工作 - 您可以假设任何不以
.in.
开头的文件都是一个完成上传。您还可以在某个整理脚本中任意一段不活动时间后安全地删除任何孤立的.in.*
文件。Looking at the proftpd docs, I see http://www.proftpd.org/docs/directives/linked/config_ref_HiddenStores.html
This should be the "better way" to solve the problem when you have control of proftpd as it handles all the work for you - you can assume that any file which doesn't start
.in.
is a completed upload. You can also safely delete any orphan.in.*
files after some arbitrary period of inactivity in a tidy-up script somewhere.如果您的 pure-ftpd 安装是用以下命令编译的,则可以使用 pure-uploadscript
--with-uploadscript
选项。它用于在每次上传完全完成后启动指定的脚本。
touch /tmp/script.sh
的命令创建一个脚本在其中写入代码。在我的示例中,脚本重命名文件并在文件名前添加“.completed”:
<代码>#!/bin/bash
完整路径=$1
文件名=$(基本名“$1”)
目录名=${完整路径%/*}
mv "$fullpath" "$dirname/completed.$filename"
运行
chmod 755 /tmp/script.sh
使脚本可以通过pure-uploadscript执行然后运行命令
pure-uploadscript -B -r /etc/pure-ftpd/uploadscript.sh
现在
/tmp/script.sh
将在每次完成上传后启动。You can use pure-uploadscript if your pure-ftpd installation was compiled with
--with-uploadscript
option.It is used to launch a specified script after every upload is completely finished.
touch /tmp/script.sh
Write the code in it. In my example the script renames the file and adds ".completed" before the file name:
#!/bin/bash
fullpath=$1
filename=$(basename "$1")
dirname=${fullpath%/*}
mv "$fullpath" "$dirname/completed.$filename"
Run
chmod 755 /tmp/script.sh
to make the script executable by pure-uploadscriptThen run a command
pure-uploadscript -B -r /etc/pure-ftpd/uploadscript.sh
Now
/tmp/script.sh
will be launched after each completed upload.