Skip to content

Commit 0034da8

Browse files
committed
Fix 26 to support remote to local copying as well as local to remote.
Issue support rsync from remote to local fabric#38 Patch from GH @MacHu-GWU
1 parent d653591 commit 0034da8

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

patchwork/transfers.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def rsync(
1414
strict_host_keys=True,
1515
rsync_opts="",
1616
ssh_opts="",
17+
remote_to_local=False,
1718
):
1819
"""
1920
Convenient wrapper around your friendly local ``rsync``.
@@ -123,11 +124,18 @@ def rsync(
123124
options = "{delete}{exclude} -pthrvz {extra} {rsh}".format(**options_map)
124125
# Create and run final command string
125126
# TODO: richer host object exposing stuff like .address_is_ipv6 or whatever
127+
# Patch for Issue support rsync from remote to local #38 from GitHub @MacHu-GWU Fix 26
126128
if host.count(":") > 1:
127129
# Square brackets are mandatory for IPv6 rsync address,
128130
# even if port number is not specified
129-
cmd = "rsync {} {} [{}@{}]:{}"
131+
if remote_to_local:
132+
cmd = "rsync {options} [{user}@{host}]:{target} {source}"
133+
else:
134+
cmd = "rsync {options} {source} [{user}@{host}]:{target}"
130135
else:
131-
cmd = "rsync {} {} {}@{}:{}"
132-
cmd = cmd.format(options, source, user, host, target)
133-
return c.local(cmd)
136+
if remote_to_local:
137+
cmd = "rsync {options} {user}@{host}:{target} {source}"
138+
else:
139+
cmd = "rsync {options} {source} {user}@{host}:{target}"
140+
cmd = cmd.format(options=options, source=source, user=user, host=host, target=target)
141+
return c.local(cmd)

0 commit comments

Comments
 (0)