Timeout in paramiko (python)

前端 未结 1 1331
礼貌的吻别
礼貌的吻别 2020-12-29 05:14

I\'m looking for a way to set a timeout for this:

transport = paramiko.Transport((host, port))
transport.connect(username = username, password = password)
sf         


        
相关标签:
1条回答
  • 2020-12-29 05:59

    The connection timeout can be set with the timeout parameter (that indicated the number of seconds for the time out as described here) of the connect function.

    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(host, username=username, password=password, timeout=10)
    sftp = ssh.open_sftp()
    sftp.get(remotepath, localpath)
    sftp.close()
    
    0 讨论(0)
提交回复
热议问题