ZeroGodForce
ZeroGodForce

Reputation: 143

Getting an Unexpected remote arg error when trying to run rsync in python subprocess

I am trying to make an Rsync call in python 3.4 using the call() method of the subprocess module and public keys for authentication, so that I can sync a remote folder. The location of the folder is passed in dynamically via JSON. The code involved is as follows:

response_dict = json.loads(response)
source = '[email protected]:' + response_dict['path'] + '/'
args = ['rsync', '-rv', '-e', '--delete', '--progress', '--update', 'ssh', '-i', '/path/to/public.key', source, '/path/to/local/folder/']
call(args)

I've tried several variations of the command, including:

args = ['rsync', '-rv', '-e', 'ssh', '-i', '/path/to/public.key', source, '/path/to/local/folder/', '--delete', '--progress', '--update']

and

args = ['rsync', '-rv', '-e', 'ssh', '-i', '/path/to/public.key', '-l', 'user', source, '/path/to/local/folder/', '--delete', '--progress', '--update']

and even

args = ['rsync', '-rv', '-e', 'ssh', '-i', '/path/to/public.key', '-l', 'user', '[email protected]:' + response_dict['path'] + '/', '/path/to/local/folder/', '--delete', '--progress', '--update']

But I get the same error:

Unexpected remote arg: [email protected]:/path/to/remote/folder/ 
rsync error: syntax or usage error (code 1) at main.c(1330) [sender=3.1.1]

I'm new to python and am pretty much learning as I go along, but this one has me completely stumped. I've been googling for the whole day and most of yesterday, but every solution to a similar problem I've found has had no effect. If someone could help me figure out what's going wrong, it'd be much appreciated.

Upvotes: 4

Views: 5946

Answers (1)

Alasdair
Alasdair

Reputation: 308909

First, you should verify that the ssh command works. If it doesn't, then there isn't any point trying to get it to work in Python.

Secondly, the -e command should be a single string, e.g.

args = ["rsync", "-rv", "-e", "ssh -i /path/to/public.key", "[email protected]:/path/to/remote/folder/", "/path/to/local/folder/", "--delete", "--progress" "--update"]

Upvotes: 3

Related Questions