我需要在我的FTP服务器上获取最新的文件/目录(今天更新),我发现了这个解决方案:
def callback(line):
try:
#only use this code if you'll be dealing with that FTP server alone
#look into dateutil module which parses dates with more flexibility
when = datetime.strptime(re.search('[A-z]{3}\s+\d{1,2}\s\d{1,2}:\d{2}', line).group(0), "%b %d %H:%M")
today = datetime.today()
if when.day == today.day and when.month == today.month:
pass
print "Updated file"
#####THE CODE HERE#######
except:
print "failed to parse"
return
ftp.retrlines('LIST', callback)但是:通过这段代码,我只能得到“未解析失败”的倍数,并且还会倍数“更新文件” - 打印。但是我需要今天更新文件/目录的文件/目录名称。什么是代码粘贴在“#####这里代码#######” - 部分获取目录名?