diff --git a/pyinfra/connectors/ssh.py b/pyinfra/connectors/ssh.py index ff3c1f19d..50fb5e7f9 100644 --- a/pyinfra/connectors/ssh.py +++ b/pyinfra/connectors/ssh.py @@ -517,6 +517,11 @@ def put_file( logger.error("File upload error: {0}".format(output.stderr)) return False + rm_arguments = arguments.copy() + # _chdir is the only one of the global arguments that could require _sudo to succeed + # and _sudo isn't present in arguments as removed above + rm_arguments.pop("_chdir", False) + # Delete the temporary file now that we've successfully copied it command = StringCommand("rm", "-f", temp_file) @@ -524,7 +529,7 @@ def put_file( command, print_output=print_output, print_input=print_input, - **arguments, + **rm_arguments, ) if status is False: