How do I copy a directory to a remote machine using Fabric?

后端 未结 4 1168
刺人心
刺人心 2020-11-29 18:31

I have a directory on my local machine that I would like to copy to a remote machine (and rename it) using Fabric. I know I can copy file using put(), but what

4条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 19:08

    You can use put for that as well (at least in 1.0.0):

    local_path may be a relative or absolute local file or directory path, and may contain shell-style wildcards, as understood by the Python glob module. Tilde expansion (as implemented by os.path.expanduser) is also performed.

    See: http://docs.fabfile.org/en/1.0.0/api/core/operations.html#fabric.operations.put


    Update: This example works fine (for me) on 1.0.0.:

    from fabric.api import env
    from fabric.operations import run, put
    
    env.hosts = ['frodo@middleearth.com']
    
    def copy():
        # make sure the directory is there!
        run('mkdir -p /home/frodo/tmp')
    
        # our local 'testdirectory' - it may contain files or subdirectories ...
        put('testdirectory', '/home/frodo/tmp')
    
    # [frodo@middleearth.com] Executing task 'copy'
    # [frodo@middleearth.com] run: mkdir -p /home/frodo/tmp
    # [frodo@middleearth.com] put: testdirectory/HELLO -> \
    #     /home/frodo/tmp/testdirectory/HELLO
    # [frodo@middleearth.com] put: testdirectory/WORLD -> \
    #     /home/frodo/tmp/testdirectory/WORLD
    # ...
    

提交回复
热议问题