如何使用Fabric将目录复制到远程计算机? [英] How do I copy a directory to a remote machine using Fabric?

查看:118
本文介绍了如何使用Fabric将目录复制到远程计算机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地计算机上有一个目录,我想使用Fabric将其复制到远程计算机上(并重命名).我知道我可以使用put()复制文件,但是目录呢.我知道使用 scp 很容易,但是如果可能的话,我宁愿在我的fabfile.py内部进行.

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 about a directory. I know it's easy enough using scp, but I would prefer to do it from within my fabfile.py if possible.

推荐答案

您也可以使用put(至少在1.0.0中使用):

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

local_path可能是相对或绝对本地文件或目录路径,并且可能包含 shell样式的通配符,如Python glob 模块.还可以进行波浪扩展(由os.path.expanduser实现).

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.

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

更新:此示例对1.0.0来说(对我而言)工作正常.

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
# ...

这篇关于如何使用Fabric将目录复制到远程计算机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆