diff --git a/patchwork/transfers.py b/patchwork/transfers.py index e7292da..b70b15d 100644 --- a/patchwork/transfers.py +++ b/patchwork/transfers.py @@ -9,6 +9,7 @@ def rsync( c, source, target, + from_local=True, exclude=(), delete=False, strict_host_keys=True, @@ -59,7 +60,9 @@ def rsync( ``source`` will be created inside of it. So ``rsync(c, "foldername", "/home/username")`` would create a new directory ``/home/username/foldername`` (if needed) and place the files there. - + :param bool from_local: + Optional, indicates if the copy should be done from local to remote or + the other way around. The default is from local to remote. :param exclude: Optional, may be a single string or an iterable of strings, and is used to pass one or more ``--exclude`` options to ``rsync``. @@ -126,8 +129,14 @@ def rsync( if host.count(":") > 1: # Square brackets are mandatory for IPv6 rsync address, # even if port number is not specified - cmd = "rsync {} {} [{}@{}]:{}" + cmd_remote = '[{}@{}]' + else: + cmd_remote = '{}@{}' + + if from_local: + cmd = "rsync {} {} " + cmd_remote + ":{}" + cmd = cmd.format(options, source, user, host, target) else: - cmd = "rsync {} {} {}@{}:{}" - cmd = cmd.format(options, source, user, host, target) + cmd = "rsync {} " + cmd_remote + ":{} {}" + cmd = cmd.format(options, user, host, source, target) return c.local(cmd)