From 1341e28882998a08fa2bf00c21047207dff3e18a Mon Sep 17 00:00:00 2001 From: Jeff Forcier Date: Sun, 14 Oct 2012 21:46:50 -0700 Subject: [PATCH] Move SFTPClient.get() termination condition to loop end. Ensures callback always executes even for zero-len files. Fixes #90 --- NEWS | 4 ++++ paramiko/sftp_client.py | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 7a08dea..de83fb2 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,10 @@ Releases v1.8.1 (DD MM YYYY) ------------------- +* #90: Ensure that callbacks handed to `SFTPClient.get()` always fire at least + once, even for zero-length files downloaded. Thanks to Github user `@enB` for + the catch. + v1.8.0 (3rd Oct 2012) --------------------- diff --git a/paramiko/sftp_client.py b/paramiko/sftp_client.py index f446ba3..3eaefc9 100644 --- a/paramiko/sftp_client.py +++ b/paramiko/sftp_client.py @@ -612,12 +612,12 @@ class SFTPClient (BaseSFTP): size = 0 while True: data = fr.read(32768) - if len(data) == 0: - break fl.write(data) size += len(data) if callback is not None: callback(size, file_size) + if len(data) == 0: + break finally: fl.close() finally: