def copy_remote_directory_to_local(sftp, remote_path, local_path):
    '''copy remote directory to local machine'''
    try:
        os.makedirs(local_path, exist_ok=True)
        files = sftp.listdir(remote_path)
        for file in files:
            remote_full_path = os.path.join(remote_path, file)
            local_full_path = os.path.join(local_path, file)
            try:
                if sftp.listdir(remote_full_path):
                    copy_remote_directory_to_local(sftp, remote_full_path, local_full_path)
            except:
                sftp.get(remote_full_path, local_full_path)
    except Exception:
        pass
def copy_remote_directory_to_local ( sftp , remote_path , local_path ) : try : os . makedirs ( local_path , exist_ok = True ) files = sftp . listdir ( remote_path ) for file in files : remote_full_path = os . path . join ( remote_path , file ) local_full_path = os . path . join ( local_path , file ) try : if sftp . listdir ( remote_full_path ) : copy_remote_directory_to_local ( sftp , remote_full_path , local_full_path ) except : sftp . get ( remote_full_path , local_full_path ) except Exception : pass
copy remote directory to local machine