我在本地计算机上有一个目录,我想使用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.
请参阅: docs.fabfile /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'] 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] Executing task 'copy' # [frodo@middleearth] run: mkdir -p /home/frodo/tmp # [frodo@middleearth] put: testdirectory/HELLO -> \ # /home/frodo/tmp/testdirectory/HELLO # [frodo@middleearth] put: testdirectory/WORLD -> \ # /home/frodo/tmp/testdirectory/WORLD # ...更多推荐
如何使用Fabric将目录复制到远程计算机?
发布评论