简体   繁体   English

如何在 Python 中的 FTP 服务器上监视现有文件名

[英]How to monitor existing filenames on a FTP server in Python

I need to monitor continuously an FTP server where images appear regularly (every second or so), copy them on my client PC and delete them.我需要持续监控 FTP 服务器,其中图像定期出现(每秒左右),将它们复制到我的客户端 PC 上并删除它们。 Deleting the images on the server is optional but I need to have this option, and I would be using Python for all this.删除服务器上的图像是可选的,但我需要有这个选项,我将使用 Python 来完成这一切。

I understand that the FTP protocol has no API to notify a client about changes .我了解 FTP 协议没有 API 通知客户有关更改 This is why current solution of choice is to run a.py script containing a variation of this well-upvoted answer : read all the filenames (most of the time just one), copy and delete them all, then sleep a few dozens milliseconds.这就是为什么当前选择的解决方案是运行 a.py 脚本,其中包含这个广受好评的答案的变体:读取所有文件名(大多数时候只有一个),复制并删除它们,然后休眠几十毫秒。

The python script will run continuously, with Windows Task scheduler trying to start it again if dead every few minutes. python 脚本将连续运行,Windows 任务调度程序每隔几分钟就会尝试重新启动它。 Is this a particularly sketchy solution (especially "while True: ... sleep(0.01)"), and what would a more conventional alternative be?这是一个特别粗略的解决方案(尤其是“while True: ... sleep(0.01)”),更传统的替代方案是什么?

Sounds good to me.听起来不错。 This script should be very light so it shouldn't be a problem if it's continuously working.这个脚本应该很轻,所以如果它连续工作应该不会有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM