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