If polling the server is an option:
from ftplib import FTP
from time import sleep
ftp = FTP('localhost')
ftp.login()
def changemon(dir='./'):
ls_prev = set()
while True:
ls = set(ftp.nlst(dir))
add, rem = ls-ls_prev, ls_prev-ls
if add or rem: yield add, rem
ls_prev = ls
sleep(5)
for add, rem in changemon():
print('
'.join('+ %s' % i for i in add))
print('
'.join('- %s' % i for i in remove))
ftp.quit()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…