ftp获取远程文件时间
from ftplib import FTP
from dateutil import parser
# ... (connection to FTP)
timestamp = ftp.voidcmd("MDTM /remote/path/file.txt")[4:].strip()
time = parser.parse(timestamp)
print(time)
或
from ftplib import FTP
from dateutil import parser
# ... (connection to FTP)
files = ftp.mlsd("/remote/path")
for file in files:
name = file[0]
timestamp = file[1]['modify']
time = parser.parse(timestamp)
print(name + ' - ' + str(time))
或
lines = []
ftp.dir("/remote/path", lines.append)
for line in lines:
tokens = line.split(maxsplit = 9)
name = tokens[8]
time_str = tokens[5] + " " + tokens[6] + " " + tokens[7]
time = parser.parse(time_str)
print(name + ' - ' + str(time))