From 8ec2cd9a118f3571c4cb7237ba71fd5f2b2dbaa9 Mon Sep 17 00:00:00 2001 From: renaud gaudin Date: Wed, 30 Mar 2022 22:50:12 +0000 Subject: [PATCH] Using sftp for mkdir step As there is no shell, use SFTP's mkdir command to create the folders up to final path. --- .github/scripts/common.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/scripts/common.py b/.github/scripts/common.py index 3ba0d26..d3e7b1b 100644 --- a/.github/scripts/common.py +++ b/.github/scripts/common.py @@ -173,22 +173,31 @@ def upload(file_to_upload, host, dest_path): else: port = "22" + # sending SFTP mkdir command to the sftp interactive mode and not batch (-b) mode + # as the latter would exit on any mkdir error while it is most likely + # the first parts of the destination is already present and thus can't be created + sftp_commands = "\n".join( + [ + f"mkdir {part}" + for part in list(reversed(Path(dest_path).parents)) + [dest_path] + ] + ) command = [ - "ssh", - "-p", - port, + "sftp", "-i", _environ.get("SSH_KEY"), + "-P", + port, "-o", "StrictHostKeyChecking=no", host, - "mkdir -p {}".format(dest_path), ] print_message("Creating dest path {}", dest_path) - subprocess.check_call(command) + subprocess.run(command, input=sftp_commands.encode("utf-8"), check=True) command = [ "scp", + "-r", "-P", port, "-i",