From 98d5f7c43312e5cba33d7dca38b3fcffc10cd645 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Mon, 12 Aug 2013 16:20:11 +0200 Subject: ftp: ignore ms in mlsd, process path in ftp-get - ftp-get: when 'get bar.ext' on ftp.example.com/foo/, the directory 'foo' won't be created. --- ftp-get.py | 9 ++++++--- ftp-list.py | 1 + ftp.py | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ftp-get.py b/ftp-get.py index c3da943..c7e6fab 100755 --- a/ftp-get.py +++ b/ftp-get.py @@ -48,7 +48,10 @@ if len(sys.argv) >= 2: port = int(m.group("port")) if m.group("path") is not None: path = m.group("path") - print("Warning: path component is ignored", file=sys.stderr) + if not path.endswith("/"): + print("Path must be a directory", + file=sys.stderr) + sys.exit(1) if host is None: print("Usage: python", sys.argv[0], @@ -59,11 +62,11 @@ if host is None: files = [] for line in sys.stdin: - file_path = line.rstrip("\r\n") + file_path = line.rstrip("\r\n").lstrip("/") # note: os.path.join(outdir, file_path) throws away if file_path # is absolute. That is *not* intended here. local_file_path = outdir + "/" + file_path - files.append((file_path, local_file_path)) + files.append((path + file_path, local_file_path)) if not files: print("Nothing to do", file=sys.stderr) diff --git a/ftp-list.py b/ftp-list.py index 057b117..8aa073c 100755 --- a/ftp-list.py +++ b/ftp-list.py @@ -126,6 +126,7 @@ def format_type_fact(type): return "?" def dt_from_ftp(timeval): + timeval = timeval.split(".")[0] return datetime.strptime(timeval, "%Y%m%d%H%M%S").replace(tzinfo=timezone.utc) def format_mlsd(name, facts): diff --git a/ftp.py b/ftp.py index c6ca471..3d6565c 100755 --- a/ftp.py +++ b/ftp.py @@ -93,6 +93,7 @@ def format_type_fact(type): return "?" def dt_from_ftp(timeval): + timeval = timeval.split(".")[0] return datetime.strptime(timeval, "%Y%m%d%H%M%S").replace(tzinfo=timezone.utc) def format_mlsd(name, facts): -- cgit v1.2.1