python, paramiko, ssh exception ssh session not active

倖福魔咒の 提交于 2019-11-29 11:09:53

Alright you guys, I didn't firgure out why I was getting these errors. But I did find a work around. After creating the SSHClient, using connect, you can can Invoke_Shell, and it opens a channel, that it doesn't close after you send something through it, which is great. Below is my updated connectSwitch code, that utilizes this work around.

def connectSwitch(UUser, UPass, Host):#SSH connection to Switch
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(Host, port=22, username=UUser, password=UPass)
    print "\n\nNewInvoke Shell\n"

    chan = ssh.invoke_shell()
    resp = chan.recv(9999)
    print resp

    print chan.send_ready()
    chan.send('copy running-config tftp\n')
    time.sleep(3)
    resp = chan.recv(9999)
    print resp

    chan.send('138.86.51.189\n')
    time.sleep(3)
    resp = chan.recv(9999)
    print resp


    chan.send('Backups/'+filename+'/'+Host+'\n')
    time.sleep(3)
    resp = chan.recv(9999)
    print resp
    print"\nEnd invoke Shell\n\n"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!