From d9e4a347b08b165e277ede8efcb5c7a238519bba Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 14 Jul 2013 16:42:02 +0200 Subject: ftp-list: detect availability of MLSD Some ProFTPd are known not to support MLSD. Detect that by checking for MLST in FEAT per RFC 3659[1]. [1]: http://tools.ietf.org/html/rfc3659#page-49 --- ftp-list.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'ftp-list.py') diff --git a/ftp-list.py b/ftp-list.py index 3d7a21b..057b117 100755 --- a/ftp-list.py +++ b/ftp-list.py @@ -13,7 +13,8 @@ from ftplib import FTP import re from datetime import datetime, timezone, date -use_list = False +# None = auto-detect (FEAT), True = use LIST, False = use MLSD +use_list = None user = "anonymous" passwd = "anon" @@ -156,10 +157,22 @@ def format_mlsd(name, facts): line += " " + date_str + " " + name return line +def get_features(ftp): + """Returns supported FTP features (FEAT) in a list""" + # cut "211-Features" and "211 End" + feats = ftp.sendcmd("FEAT").splitlines()[1:-1] + return [ f.strip() for f in feats ] + with FTP() as ftp: ftp.connect(host, port) ftp.login(user, passwd) print(ftp.getwelcome(), file=sys.stderr) + feats = get_features(ftp) + + if use_list is None: + # use list only if supported + use_list = not any(f.startswith("MLST ") for f in feats) + while dirs: dir = dirs.pop() ftp.cwd(dir) -- cgit v1.2.1