Skip to content

Commit

Permalink
adding special case situation
Browse files Browse the repository at this point in the history
  • Loading branch information
jrybicki-jsc committed Dec 22, 2023
1 parent 7833f06 commit c9f7b33
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ssh2ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,18 @@ 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"])
print("Processing", fname, "-->", target_name)

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)
Expand Down
6 changes: 6 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down

0 comments on commit c9f7b33

Please sign in to comment.