Timeout in paramiko (python)
61,478
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()
Related videos on Youtube
Author by
Kukosk
Updated on April 04, 2020Comments
-
Kukosk about 4 years
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()
-
manoj prashant k over 6 years@kukosk It would help if you mentioned the unit in which timeout is to be given, I guess its seconds.
-
jxramos almost 6 yearsWhat's the default timeout, I don't think I found it mentioned in the docs either, although they do mention
timeout (float) – an optional timeout (in seconds) for the TCP connect
-
jxramos almost 6 yearsHere's some more background, if timeout is not specified the client falls into blocking mode: docs.python.org/3/library/socket.html#socket-timeouts
-
jxramos almost 6 yearsLots of default timeout definitions pop up at github.com/jbouse-debian/paramiko/blob/master/paramiko/…, all given in seconds
-
trozen about 5 yearsNote that
timeout
parameter sets TCP timeout. There are alsobanner_timeout
andauth_timeout
which you may want to adjust as well. -
chrisinmtown almost 2 years@jxramos are you sure about blocking behavior? When I tested an unreachable address with no timeout argument, the connect timed out after 75 seconds.