How to get notify whenever a file is started to upload in FTP server?

蹲街弑〆低调 提交于 2021-02-08 11:59:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!