每当文件开始在FTP服务器中上载时,如何获取通知? [英] How to get notify whenever a file is started to upload in FTP server?

查看:87
本文介绍了每当文件开始在FTP服务器中上载时,如何获取通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在文件开始在FTP服务器上开始上传以及ftp目录中没有文件上传超过10分钟时得到通知.有什么方法可以告诉我该文件已开始在FTP服务器上上传(使用Python)?

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)?

推荐答案

我认为以下代码将解决您的问题,只需将其与服务器连接即可.您也可以在本地目录中尝试.

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

这篇关于每当文件开始在FTP服务器中上载时,如何获取通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆