From 57029a7c4c1d64f8aab98d72b3d831f30c3ae493 Mon Sep 17 00:00:00 2001 From: BryanFauble <17128019+BryanFauble@users.noreply.github.com> Date: Mon, 27 Nov 2023 14:27:01 -0700 Subject: [PATCH] Print transfer progress for FTP --- synapseclient/client.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/synapseclient/client.py b/synapseclient/client.py index 376b475f5..5de077586 100644 --- a/synapseclient/client.py +++ b/synapseclient/client.py @@ -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 @@ -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,