I have a piece of code written in Python which uses Paramiko to run a command that copies a file from one place to another on a remote server. This has been working fine for the last two years. I tried it on a new OS today (RHEL 7.9) and it kept failing. I've been trying to debug the issue but keep hitting a wall. Following is the piece of code:
dirpath = '/etc/somedir'
stdin, stdout, stderr = client.exec_command(f'sudo mv /tmp/filname.txt {dirpath}/filename.txt')
And the output
STDERR: ['mv: cannot move \xe2\x80\x98/tmp/filename.txt\xe2\x80\x99 to \xe2\x80\x98/etc/somedir/filename.txt\xe2\x80\x99: No such file or directory\\n'] ;
STDOUT: []
I am using Paramiko 2.6.0, Python 3.6.3 and the remote machine is running RHEL 7.9. I am at my wits end with it and not able to find what's wrong, as it works fine on all other machines. I also couldn't find a similar question on stack overflow. There were similar question on other sites, but no one had answered them.
The code mislead you. The \xe2\x80\x98
/9
is UTF-8 for left/right single quote. It's most likely a part of the error message formatting, not of the file name.
Your root problem is likely really what the error message says:
No such file or directory
Check both the source and target paths.
If you do this, you should get the same error:
ssh user@host sudo mv /tmp/filname.txt /etc/somedir/filename.txt