如何使用Fabric将目录复制到远程计算机?

编程入门 行业动态 更新时间:2024-10-26 08:33:05
本文介绍了如何使用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.

请参阅: 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将目录复制到远程计算机?

本文发布于:2023-10-17 02:54:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1499562.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   计算机   目录   Fabric

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!