Using sftp for mkdir step
As there is no shell, use SFTP's mkdir command to create the folders up to final path.
This commit is contained in:
parent
1351fc7f8b
commit
8ec2cd9a11
|
@ -173,22 +173,31 @@ def upload(file_to_upload, host, dest_path):
|
||||||
else:
|
else:
|
||||||
port = "22"
|
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 = [
|
command = [
|
||||||
"ssh",
|
"sftp",
|
||||||
"-p",
|
|
||||||
port,
|
|
||||||
"-i",
|
"-i",
|
||||||
_environ.get("SSH_KEY"),
|
_environ.get("SSH_KEY"),
|
||||||
|
"-P",
|
||||||
|
port,
|
||||||
"-o",
|
"-o",
|
||||||
"StrictHostKeyChecking=no",
|
"StrictHostKeyChecking=no",
|
||||||
host,
|
host,
|
||||||
"mkdir -p {}".format(dest_path),
|
|
||||||
]
|
]
|
||||||
print_message("Creating dest path {}", 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 = [
|
command = [
|
||||||
"scp",
|
"scp",
|
||||||
|
"-r",
|
||||||
"-P",
|
"-P",
|
||||||
port,
|
port,
|
||||||
"-i",
|
"-i",
|
||||||
|
|
Loading…
Reference in New Issue