diff --git a/src/pyinfra/connectors/ssh.py b/src/pyinfra/connectors/ssh.py index ff2e45a32..0aeab9b2a 100644 --- a/src/pyinfra/connectors/ssh.py +++ b/src/pyinfra/connectors/ssh.py @@ -603,6 +603,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) @@ -610,7 +615,7 @@ def put_file( command, print_output=print_output, print_input=print_input, - **arguments, + **rm_arguments, ) if status is False: