Search code examples
pythonsshfabric

Using fabric to copy file from one remote server to another remote server?


I need to make a service that can copy a file from one remote server to another remote server. I could just run this in a subshell:

scp user@host1:/path/to/file/video.mp4 user@host2:/path/to/file

But that doesn't seem nearly as good as using something like fabric's put command, which only copies a local file to a remote machine. I also need this to run entirely with ssh keys, no password prompting.


Solution

  • You can use get to get the file from host1 and then put to push it to host2.

    For keys, if the private key isn't in the default location, you can specify it with the -i flag, e.g.:

    fab -i /path/to/priv/key
    

    or put it in the fabfile:

    from fabric import env
    env.key_filename = '/path/to/priv/key'