I plan to move file from one system to another system. For this, I am using rsync command in linux terminal. It works fine. But I need to implement this command to python. I am very new in python, so I don't know the way of defining the rsync command. So please tell the steps to define it. This is my rsync command:

rsync -avrz /opt/data/filename root@ip:/opt/data/file 

I need to implement this command in a python script.

4

2 Answers

import os os.system("rsync -avrz /opt/data/filename root@ip:/opt/data/file") 

Did you try that?
os.system basically allows you to run bash commands.

1

As the answer to your previous similar question suggests, rsync will work just fine as a shell command from within Python if you use SSH keys to authenticate instead of a password. If you need further help with how to set up SSH key-based authentication, please edit your question.