Timeout in paramiko (python)

泪湿孤枕 提交于 2019-12-20 12:21:37

问题


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

transport = paramiko.Transport((host, port))
transport.connect(username = username, password = password)
sftp = paramiko.SFTPClient.from_transport(transport)
sftp.get(remotepath, localpath)
sftp.close()
transport.close()

回答1:


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()


来源:https://stackoverflow.com/questions/9758432/timeout-in-paramiko-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!