首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带paramiko的ssh客户端

带paramiko的ssh客户端
EN

Stack Overflow用户
提问于 2011-05-12 15:03:25
回答 1查看 2.8K关注 0票数 2
代码语言:javascript
复制
import paramiko
import os

def connection():
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    privatekey = os.path.expanduser('/home/rabia/private')
    mkey = paramiko.RSAKey.from_private_key_file(privatekey)
    ssh.connect('78.46.172.47', port=22, username='s0urd', password=None, pkey=mkey)
    stdin, stdout, stderr = ssh.exec_command('ls')
    print stdout.readlines()

connection()

如何才能使一个线程等待用户输入,而另一个线程执行ssh连接?

EN

回答 1

Stack Overflow用户

发布于 2011-05-12 19:07:33

如果我没理解错的话,那么你应该在你的代码中添加类似这样的东西:

代码语言:javascript
复制
import threading

_paramikoThread = threading.Thread(target=doParamikoConnection)
_paramikoThread.start()
# The following code is executed by parent thread.
_ans = ""
while _ans != "nay":
    _ans = raw_input("Should I loop again? [yay/nay]")
# Now we've ended user I/O session, wait for connection to complete.
_paramikoThread.join()
# At this point we have data collected from user and connection being initialised.
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5974463

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档