diff --git a/ssh2ssh.py b/ssh2ssh.py index 091f300..473ab0f 100644 --- a/ssh2ssh.py +++ b/ssh2ssh.py @@ -57,6 +57,8 @@ def copy(**context): sftp_client = source_ssh_hook.get_conn().open_sftp() sclient = RFSC(sftp_client) + target_conn = target_ssh_hook.get_conn() + mappings = list(walk_dir(client=sclient, path=s_params["path"], prefix="")) for fname in mappings: target_name = fname.replace(s_params["path"], t_params["path"]) @@ -64,9 +66,9 @@ def copy(**context): di = os.path.dirname(target_name) print("Making direcotry", di) - target_ssh_hook.get_conn().exec_command(command=f"mkdir -p {di}") + target_conn.exec_command(command=f"mkdir -p {di}") # sometimes mkdir takes longer and is not sync? - target_ssh_hook.get_conn().exec_command(command=f"touch {target_name}") + target_conn.exec_command(command=f"touch {target_name}") with target_client.open(target_name, "wb") as tr: tr.set_pipelined(pipelined=True) diff --git a/utils.py b/utils.py index 643f2e6..99dd6db 100644 --- a/utils.py +++ b/utils.py @@ -221,6 +221,12 @@ def __init__(self, client, **kwargs): self.client = client def list(self, path, get_info=True): + if file_exist(self.client, path) and not is_dir(self.client, path): + print("Special case it is a file") + if not get_info: + return [path] + return [{"path": path, "isdir": False}] + if not get_info: return [el.filename for el in self.client.listdir_attr(path)] return [