Skip to content

Commit

Permalink
Print transfer progress for FTP
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanFauble committed Nov 27, 2023
1 parent 78f2ec5 commit 57029a7
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion synapseclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2731,6 +2731,7 @@ def _download_from_URL(
actual_md5 = None
redirect_count = 0
delete_on_md5_mismatch = True
self.logger.debug(f"Downloading from {url} to {destination}")
while redirect_count < REDIRECT_LIMIT:
redirect_count += 1
scheme = urllib_urlparse.urlparse(url).scheme
Expand All @@ -2747,7 +2748,24 @@ def _download_from_URL(
)
break
elif scheme == "ftp":
urllib_request.urlretrieve(url, destination)
transfer_start_time = time.time()

def _ftp_report_hook(
block_number: int, read_size: int, total_size: int
) -> None:
show_progress = not self.silent
if show_progress:
self._print_transfer_progress(
transferred=block_number * read_size,
toBeTransferred=total_size,
prefix="Downloading ",
postfix=os.path.basename(destination),
dt=time.time() - transfer_start_time,
)

urllib_request.urlretrieve(
url=url, filename=destination, reporthook=_ftp_report_hook
)
break
elif scheme == "http" or scheme == "https":
# if a partial download exists with the temporary name,
Expand Down

0 comments on commit 57029a7

Please sign in to comment.