Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add from_local option to transfers.rsync #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ferares
Copy link

@ferares ferares commented Oct 10, 2018

'from_local' option indicates if the copy should be done from remote to local, the default is from local to remote.

closes #26

ferares and others added 2 commits October 10, 2018 14:29
'from_local' option indicates if the copy should be done from remote to local, the default is from local to remote.
The 'from_local' option had the opposite behavior to what it is supposed to do.
@abingham
Copy link

Could this be merged in? I could really use this as well.

@gerazov
Copy link

gerazov commented Apr 20, 2019

yeah, please merge 😄

@WildWeazel
Copy link

Another vote for merge please, this feature is essential

@MacHu-GWU
Copy link

#38 Ops, I just found this PR. I issued another one for the same feature.

@ferares
Copy link
Author

ferares commented Jan 24, 2020

@MacHu-GWU I made this back on 2018, the project is clearly and sadly inactive :(

@MacHu-GWU
Copy link

@ferares Is the author still active on GitHub? It is always good to have group of people maintaining open source project.

@ferares
Copy link
Author

ferares commented Jan 24, 2020

@ferares Is the author still active on GitHub? It is always good to have group of people maintaining open source project.

Yeah he is @bitprophet

@trammik
Copy link

trammik commented Sep 13, 2021

If someone is interested, here a working snippet for rsync over Fabric's method local

Simply add this to your own inherited from Connection class

    def rsync(self, source, target, exclude=(),  rsync_opts="", ssh_opts="",
              delete=False, strict_host_keys=True, upload=True):
        if isinstance(exclude, string_types):
            exclude = [exclude]
        # Double-backslash-escape
        replace_bs = lambda s: str(s).replace('"', '\\\\"')
        exclusions = " ".join((f'--exclude "{replace_bs(s)}"' for s in exclude))
        # Honor SSH key(s)
        keys = self.connect_kwargs.get("key_filename", [])
        if isinstance(keys, string_types):
            keys = [keys]
        key_string = "-i " + " -i ".join(keys) if keys else ""
        port_string = f"-p {self.port}"

        # Workaround for our old keys:
        ssh_opts += '-o "PubkeyAcceptedKeyTypes +ssh-dss"'
        # Strict host key checking
        disable_keys = "-o StrictHostKeyChecking=no"
        if not strict_host_keys and disable_keys not in ssh_opts:
            ssh_opts += " {}".format(disable_keys)
        # Remote shell (SSH) options
        rsh_parts = [key_string, port_string, ssh_opts]
        rsh_string = "--rsh='ssh {}'".format(" ".join(rsh_parts)) if any(rsh_parts) else ""
        # Set up options part of string
        options = f'{"--delete" if delete else ""}{exclusions} -pthrvz {rsync_opts} {rsh_string}'
        remote_prefix = f"{self.user}@{self.host}"
        if self.host.count(":") > 1:
            remote_prefix = f"[{remote_prefix}]"

        upload_direction = f"{source} {remote_prefix}:{target}" if upload else f"{remote_prefix}:{source} {target}"
        print(f'rsync {options} {upload_direction}')
        return self.local(f"rsync {options} {upload_direction}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

transfers.rsync don't support rsync from remote to local
6 participants