本文介紹了監(jiān)控遠(yuǎn)程FTP目錄的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
我只能通過(guò) FTP 訪問(wèn)遠(yuǎn)程服務(wù)器上的目錄,并且希望在新文件出現(xiàn)在目錄中時(shí)立即獲取它們的內(nèi)容.
I only have FTP access to a directory on a remote server and would like to get the contents of new files as soon as they appear in the directory.
有沒(méi)有類似 FAM for Python 的東西可以讓我通過(guò) FTP 監(jiān)控新文件?
Is there any thing like FAM for Python that lets me monitor for new files over FTP?
推薦答案
如果輪詢服務(wù)器是一個(gè)選項(xiàng):
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()
這篇關(guān)于監(jiān)控遠(yuǎn)程FTP目錄的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!