如何使用scp从python中的第三个本地计算机在两个远程服务器之间传输文件

2024-06-28 19:27:40 发布

您现在位置:Python中文网/ 问答频道 /正文

 I'm using paramiko to login in x machine then 
 after logged in machine x there are file in some path like 
 t="/abc/gfd/*" which 
 i want to copy to some path like 
 p=<username>@<machine-name/ip>:/dfg/hgf/kjh/.

cmd="pwd; scp {0} {1}".format(t,p)
pwd_of_machine_p="xyz"
cmd="xyz; scp {0} {1}".format(t,p)

then executing this cmd with paramiko obj like
client.exec_command(cmd)
which is not working .

当我沿着这条路径“/dfg/hgf/kjh/”时,我什么也没有。在


Tags: topathincmdparamikowhichpwdsome
1条回答
网友
1楼 · 发布于 2024-06-28 19:27:40

您可以使用下面的简单方法而不使用paramiko。在

import os
os.system("scp FILE USER@DEST_MACHINE:PATH")
#e.g. os.system("scp file.txt sunilt@xx.xx.xx.xx:/path/")

但在此之前,您需要在源计算机上生成一个ssh密钥并将其复制到目标计算机,这样scp就可以自动使用您的公共ssh密钥进行身份验证,并且脚本不需要密码。在

有关生成和复制ssh密钥的信息是@ssh_keygen_exapmple

相关问题 更多 >