1ftp = FTP(host="127.0.0.1", user="u",passwd="p")
2ftp.cwd("/data")
3file_name = sorted(ftp.nlst(), key=lambda x: ftp.voidcmd(f"MDTM {x}"))[-1]
1from dateutil import parser
2
3# ...
4
5lines = []
6ftp.dir("", lines.append)
7
8latest_time = None
9latest_name = None
10
11for line in lines:
12 tokens = line.split(maxsplit = 9)
13 time_str = tokens[5] + " " + tokens[6] + " " + tokens[7]
14 time = parser.parse(time_str)
15 if (latest_time is None) or (time > latest_time):
16 latest_name = tokens[8]
17 latest_time = time
18
19print(latest_name)