Search code examples
pythonsshrsyncpopen

python move files on remote host


I have a python script that needs to move a directory on a remote host from one location to another.

From a terminal, I can ssh into the remote host and then mv -r src dest will mv the relevant directory on that remote host.

> ssh USER@REMOTE
> mv -r SRC DEST

How can I do this through python?


Solution

  • import paramiko
    ssh = paramiko.SSHClient()
    ssh.connect('REMOTE', username='USER', 
        password='PASSWORD')
    stdin, stdout, stderr = \
    ssh.exec_command("mv -r SRC DEST")