我想使用python從FTP服務器下載最新文件。我能夠連接到服務器并下載特定目錄中的所有文件,但是我不知道如何在主題中查找帶有特定關鍵字的最新文件。以下是我正在使用的代碼。但是它將返回所有帶有* .png鍵名的文件。我不知道如何在這里應用os.path.getctime來獲取最新文件。這就是我想要的所有幫助。 import ftplib import os ftp = ftplib.FTP('test.rebex.net', 'demo','password') ftp.retrlines('LIST') ftp.cwd("/pub") ftp.retrlines('LIST') ftp.cwd("example") ftp.retrlines('LIST') filematch='*.png' target_dir='C:/Users/muzamal.pervez/Desktop/OPD Claims' for filename in ftp.nlst(filematch): target_file_name = os.path.join(target_dir,os.path.basename(filename)) with open(target_file_name,'wb') as fhandle: ftp.retrbinary('RETR %s' %filename, fhandle.write)
添加回答
舉報
0/150
提交
取消