def _download_file( self, indentationlevel: int, sftp: paramiko.SFTPClient, remote_root: Path, localfile: Path, remote_filenode: Path, entry: BackupEntry ): options = entry.get_options() has_options = is_sequence_with_any_elements(options) is_simulation = False if has_options is True: is_simulation = options["simulate"] if "simulate" in options and options["simulate"] is True else False indentation = repeat("\t", indentationlevel+1) if not is_simulation: stat_remote = sftp.lstat(str(remote_filenode)) do_transfer = True self.info("{}Processing file: '{}'".format(indentation, remote_filenode)) if has_options and not is_simulation: do_transfer = self._check_file_with_options( options, remote_root, localfile, remote_filenode, stat_remote, indentation ) if do_transfer is not None: self.info("{}Excluding '{}' due to json-file-option {}".format( indentation, remote_filenode, do_transfer )) else: if is_simulation: self.info("{}Simulating download of file '{}'".format(indentation, remote_filenode)) else: self.info("{}Downloading file (Total: {})".format( indentation, bytes_to_unit(stat_remote.st_size, 1, True, False)) ) self._current_progress_divider = get_filesize_progress_divider(stat_remote.st_size) sftp.get(str(remote_filenode), str(localfile)) if self._copystats: self.info("{}Copying file modification dates".format(indentation)) utime(str(localfile), (stat_remote.st_atime, stat_remote.st_mtime))
def download_file(sftp: paramiko.SFTPClient, sync_remote=r'/root/sync', local_path='D:\\sync\\'): remote_all = files_of_dir(sftp, sync_remote) for file in remote_all: name = str(file).replace(sync_remote, '') name = name[1:] if name.startswith("/") else name local = os.path.join(local_path, name) abs_path = os.path.abspath(os.path.dirname(local)) if not os.path.exists(abs_path): os.makedirs(abs_path) print("downloading: ", local) sftp.get(file, local)
async def pull_file(ftp: paramiko.SFTPClient, ftp_path: str, local_path: str): """Pulls file from remote path to local path only if out of date.""" if compare_files(ftp, ftp_path, local_path): ftp.get(ftp_path, local_path) else: print("Local is up to date.")