我需要将一些文件放到远程 sftp 服务器上,创建一个新目录来放置它们。有没有办法使用 fabric 做到这一点? Fabric.operations.put() 看起来无法在远程端创建新目录。
最佳答案
在调用 put()
之前运行 mkdir
:
run('mkdir -p /path/to/dir/')
put('/local/path/to/myfile', '/path/to/dir/')
-p
flag处理创建嵌套目录,请参阅:
-p, --parents
no error if existing, make parent directories as needed
更新(仅用于 sftp 访问)。
使用 SFTP.mkdir()
:
from contextlib import closing
from fabric.sftp import SFTP
ftp = SFTP(env.host_string)
with closing(ftp) as ftp:
ftp.mkdir('/path/to/dir/', use_sudo=False)
put('/local/path/to/myfile', '/path/to/dir/')
关于python - 使用 fabric.operations.put() 创建远程目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24946974/