@@ -221,7 +221,13 @@ def download_folder(self,
221221 logger .debug (f'{ remote_folder_path } does not exist on { self .server } .' )
222222 try :
223223 self ._sftp .chdir (remote_folder_path )
224- for item in self ._sftp .listdir_attr ():
224+ items = self ._sftp .listdir_attr ()
225+
226+ # Count the number of files to download for progress logging
227+ total_files = sum (1 for item in items if stat .S_ISREG (item .st_mode ))
228+ downloaded_files = 0
229+
230+ for item in items :
225231 # Get the remote item's name and full path
226232 filename = item .filename
227233 remote_filepath = remote_folder_path + '/' + filename
@@ -233,12 +239,19 @@ def download_folder(self,
233239 # stat.S_ISREG(item.st_mode) is True if item is a file (not a folder)
234240 if stat .S_ISREG (item .st_mode ):
235241 self ._sftp .get (remote_filepath , local_filepath )
242+ downloaded_files += 1
243+
244+ # Log progress every 10%
245+ progress = downloaded_files / total_files * 100
246+ if progress % 10 == 0 :
247+ logger .info (f'Downloaded { progress } % of files from { remote_folder_path } ' )
236248
237249 # Recursively download folders
238250 # stat.S_ISDIR(item.st_mode) is True if item is a folder
239251 elif stat .S_ISDIR (item .st_mode ):
240252 # create the folder in the local path
241253 os .makedirs (local_filepath , exist_ok = True )
254+ # recursively download the folder items
242255 self .download_folder (remote_filepath , local_filepath )
243256 except IOError :
244257 logger .warning (f'Got an IOError when trying to download file '
@@ -423,7 +436,7 @@ def _connect(self) -> Tuple[paramiko.sftp_client.SFTPClient, paramiko.SSHClient]
423436 # 15 seconds (default in paramiko) due to network congestion, faulty switches,
424437 # etc..., common solution is enlarging the timeout variable.
425438 ssh .connect (hostname = self .address , username = self .un , banner_timeout = 200 , key_filename = self .key )
426- except :
439+ except paramiko . ssh_exception . SSHException :
427440 # This sometimes gives "SSHException: Error reading SSH protocol banner[Error 104] Connection reset by peer"
428441 # Try again:
429442 ssh .connect (hostname = self .address , username = self .un , banner_timeout = 200 , key_filename = self .key )
@@ -564,6 +577,8 @@ def _check_file_exists(self,
564577 stdout , _ = self ._send_command_to_server (command , remote_path = '' )
565578 if len (stdout ):
566579 return True
580+ else :
581+ return False
567582
568583 def _check_dir_exists (self ,
569584 remote_dir_path : str ,
@@ -581,6 +596,8 @@ def _check_dir_exists(self,
581596 stdout , _ = self ._send_command_to_server (command )
582597 if len (stdout ):
583598 return True
599+ else :
600+ return False
584601
585602 def _create_dir (self , remote_path : str ) -> None :
586603 """
0 commit comments