问题
I want to get notify whenever the file is started to upload in FTP server and whenever there is no file upload in the ftp directory more than 10 minute. Is there any method to tell me that file is started to upload in FTP server (in Python)?
回答1:
I think the below code will solve your problem you just need to connect it with your server. You can try in your local directory also.
import os, time
path_to_watch = "test_ftp/"
flag = 0
before = dict ([(f, None) for f in os.listdir (path_to_watch)])
while 1:
time.sleep (10)
after = dict ([(f, None) for f in os.listdir (path_to_watch)])
added = [f for f in after if not f in before]
print added
removed = [f for f in before if not f in after]
if added:
print "Added: ", ", ".join (added)
if flag==0:
print "Notify me once"
flag =1
if removed: print "Removed: ", ", ".join (removed)
if after == before:
print "No files uploaded in 10 minutes"
break
before = after
来源:https://stackoverflow.com/questions/55585787/how-to-get-notify-whenever-a-file-is-started-to-upload-in-ftp-server