summaryrefslogtreecommitdiff
path: root/ftp-list.py
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2013-07-14 16:42:02 +0200
committerPeter Wu <lekensteyn@gmail.com>2013-07-14 16:42:02 +0200
commitd9e4a347b08b165e277ede8efcb5c7a238519bba (patch)
treeda3b7e6fc7f59fe1dc465256d74b5cdda7ec62b9 /ftp-list.py
parent1483335f34daeb7e488c6793e3265946096079ad (diff)
downloadscripts-d9e4a347b08b165e277ede8efcb5c7a238519bba.tar.gz
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
Diffstat (limited to 'ftp-list.py')
-rwxr-xr-xftp-list.py15
1 files changed, 14 insertions, 1 deletions
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)