How to monitor existing filenames on a FTP server in Python

Question:

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. Deleting the images on the server is optional but I need to have this option, and I would be using Python for all this.

I understand that the FTP protocol has no API to notify a client about changes. 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.

The python script will run continuously, with Windows Task scheduler trying to start it again if dead every few minutes. Is this a particularly sketchy solution (especially "while True: … sleep(0.01)"), and what would a more conventional alternative be?

Asked By: charmd

||

Answers:

Sounds good to me.
This script should be very light so it shouldn’t be a problem if it’s continuously working.

Answered By: Rayon Magique
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.