ftplib MLSD command gives 500 Unknown command
Asked Answered
B

2

6

I have been using ls = f.mlsd() to get list of files and timestamp from ftp but it gives me

ftplib.error_perm: 500 Unknown command

Is there any problem with ftp server? do i need to install anything on the server to get this command working

Boiardo answered 28/3, 2018 at 7:50 Comment(0)
H
5

In the fact, MLSD is nothing but a protocol extension introduced in RFC 3659 that may be not supported by some FTP servers. If you care about portability, it's better to use f.nlst() instead.

If changing something on server is acceptable for you, then I suggest you switching to proftpd which has MLSD support as a part of it's mod_facts extension.

Hospital answered 28/3, 2018 at 8:7 Comment(1)
Thanks i have switched to proftpd with mod_facts extension and MLSD command works fine nowBoiardo
L
4

MLSD command was not a part of an original FTP standard. It was added only later in RFC 3659, in 2007. While that's still quite some time ago, even now some major FTP servers do not support it. Particularly IIS and vsftpd.

If you need timestamps and yet you need to talk to a server that does not support MLSD command, you have two options:

  1. Use FTP.dir (LIST command). And parse proprietary format of file listing to retrieve the timestamps.

  2. Use FTP.nlst to retrieve a list of files (and folders). Then, use FTP.voidcmd to send MDTM command for each of the listed files. MDTM returns a file timestamp in a standardized format.

    Obviously this is a way less effective than the previous approach, but you won't have to deal with a proprietary formats of directory listings.

    Note that MDTM is not supported by all FTP servers either, but it is more widely supported than MLSD, although both commands come from the same RFC (3659). Particularly one of common Linux FTP servers, vsftpd, supports MDTM, but not MLSD.


For a code to implement both approaches see my answer to:
How to get FTP file's modify time using Python ftplib

Lynching answered 28/3, 2018 at 9:20 Comment(1)
I have switched to proftpd and enabled mod_facts and MLSD command works fine nowBoiardo

© 2022 - 2024 — McMap. All rights reserved.