summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)