I am trying implement rsync with python. Here’s my code.
#!/usr/bin/python
import os
url = raw_input("Paste your URL:")
username = raw_input("Enter username:")
#password = raw_input("Enter password:")
source = username + "@" + url
#print source
print os.system('rsync -zvr --progress source /home/zurelsoft/R')
The logic is simple: user inputs the url and username stored in source with proper formatting. The source variable is then used in rsync command. I am inputting the valid URL and username of my server but I am getting this error:
rsync: link_stat "/home/name/source" failed: No such file or directory (2)
What am I doing wrong?
You’re passing a static string. Regardless of what the user inputs, you’re always giving rsync the exact same commandline options. You probably want
sourceto be replaced with the value:As a side note, this can be done better with
subprocess:It might not matter, but you’ll close a HUGE security hole in your program this way (consider if the user put
; rm -rf ~;as their username …) and it’s always a good idea practice good programming habits.