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))

参加:How to get FTP file's modify time using Python ftplib - Stack Overflow