繁体   English   中英

scp在python的paramiko中的嵌套ssh会话中

[英]scp in a nested ssh session in python's paramiko

基本上,我在Python中使用嵌套的SSH ssh会话执行scp时遇到问题。 我使用paramiko从我的本地机器到另一台服务器建立一个SSH,让我们称之为AA。 我想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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM