[英]scp in a nested ssh session in python's paramiko
基本上,我在Python中使用嵌套的SSH ssh會話執行scp時遇到問題。 我使用paramiko
從我的本地機器到另一台服務器建立一個SSH,讓我們稱之為A和A。 我想SCP的文件,我們稱之為F到服務器B中 。 兩台服務器都有相同的密碼。 這是代碼:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=hostname, username=username, password=password)
chan = ssh.invoke_shell()
chan.send('scp f username@B:.')
buff = ''
while not buff.endswith('\'s password: '):
resp = chan.recv(9999)
buff += resp
chan.send(password + '\n')
buff = ''
while not buff.endswith('$ '):
resp = chan.recv(9999)
buff += resp
我真的不確定為什么這不起作用。 感謝任何幫助,非常感謝!
你在PyCharm中運行它嗎? 它什么時候失敗,你有任何錯誤嗎? 它可能是字符串中的
buff.endswith('\'s password: '):
與ssh會話中輸出的內容不完全匹配。 除此之外它看起來是正確的。 我建議在buff.endswith中進行breakpointing並檢查buff實際上是什么,並檢查它是否與你的字符串匹配,以及你的密碼是否與那里的換行符有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.