【问题标题】:ssh client with paramiko使用 paramiko 的 ssh 客户端
【发布时间】:2011-08-23 21:16:09
【问题描述】:
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 连接?

【问题讨论】:

    标签: python multithreading ssh paramiko


    【解决方案1】:

    如果我对您的理解正确,那么您应该在您的代码中添加类似这样的内容:

    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.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多