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.

closed as off topic by jokerdino, ish, con-f-use, John S Gruber, SirCharlo Aug 22 '12 at 13:40

Questions on Ask Ubuntu are expected to relate to Ubuntu within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    Is this Ubuntu-specific? If not, it should be migrated to StackOverflow. – ζ-- Jul 6 '12 at 13:36
  • 1
    General programming questions that are not specifically related to Ubuntu are off-topic here. You might want to try our friends in Stack Overflow for assistance. – jokerdino Jul 6 '12 at 13:44
  • 1
    This seems like a programming question as applied to a system administration task. For that reason, I'd suggest that it's on-topic here (and a better fit for our site than for Stack Overflow). I do not think we should close this question. – Eliah Kagan Jul 6 '12 at 13:49
  • 1
    Very similar to How to use tee (or generally a system) command in python? – con-f-use Aug 20 '12 at 11:14
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.

  • 6
    Please look at the subprocess module instead, where shell support is disabled by default. – Gringo Suave Dec 7 '14 at 21:59

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.