簡體   English   中英

如何使用python中的第三台本地計算機使用scp在兩個遠程服務器之間傳輸文件

[英]How to transfer a file between two remote servers using scp from a third, local machine in 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 /”時,我什么也沒得到。

您可以在不使用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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM