diff options
author | Peter Wu <lekensteyn@gmail.com> | 2013-07-13 12:36:10 +0200 |
---|---|---|
committer | Peter Wu <lekensteyn@gmail.com> | 2013-07-13 12:36:10 +0200 |
commit | a9ae058b06ef0236fc64237e5c6dc7b779e13468 (patch) | |
tree | ff91991e89b0bb18f37cfc2e8beeb9fb29c2079a /ftp.py | |
parent | a4471f71aad10433725161dff9ac39b8f23c4d77 (diff) | |
download | scripts-a9ae058b06ef0236fc64237e5c6dc7b779e13468.tar.gz |
ftp*: python3 compat, SIZE fixes, MLSD support
Set binary mode before requesting size, do not exit program if size() fails.
Support MLSD mode for ftp-list.py (mostly copied from ftp.py)
Diffstat (limited to 'ftp.py')
-rwxr-xr-x | ftp.py | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -3,6 +3,9 @@ # # Copyright (C) 2013 Peter Wu <lekensteyn@gmail.com> +from __future__ import print_function, division +# TODO: nonlocal is python3-only which makes the above useless + import sys from ftplib import FTP, all_errors import re @@ -169,7 +172,12 @@ def download_file(ftp, file_path, local_file_path, size=None, offset=0): os.makedirs(local_dirs, exist_ok=True) if size is None: - size = ftp.size(file_path) + try: + # ProFTPd requires binary mode for size + ftp.voidcmd("TYPE I") + size = ftp.size(file_path) + except all_errors as e: + print("SIZE failed: ", e, file=sys.stderr) BAR_WIDTH = 50 if size is not None: @@ -248,7 +256,12 @@ def download_file(ftp, file_path, local_file_path, size=None, offset=0): def reget_file(ftp, file_path, local_file_path): # do not send a REST(art) command when starting at the beginning offset = None - file_size = ftp.size(file_path) + try: + ftp.voidcmd("TYPE I") + file_size = ftp.size(file_path) + except all_errors as e: + print("SIZE failed: ", e, file=sys.stderr) + file_size = None if file_size is not None: try: local_size = os.path.getsize(local_file_path) |