我需要在我的 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)
但是:使用此代码,我只能得到多个“解析失败”以及多个“更新文件”打印。但我需要今天更新的文件/目录的文件/目录名称。在“#####THE CODE HERE#######”部分粘贴什么代码来获取目录名?