summaryrefslogtreecommitdiff
path: root/paramiko
diff options
context:
space:
mode:
authorRobey Pointer <robey@lag.net>2007-05-20 17:23:34 -0700
committerRobey Pointer <robey@lag.net>2007-05-20 17:23:34 -0700
commit58e26ae41bada74198abd81ebe0040fd0ea6a2b4 (patch)
tree1c370442dbe3f678e2965f769738f9f950fef2f6 /paramiko
parentafa5e0594e5095106fc9ef7824820d26fec274a6 (diff)
downloadparamiko-58e26ae41bada74198abd81ebe0040fd0ea6a2b4.tar.gz
[project @ robey@lag.net-20070521002334-6bx5g0zrnb10sgyd]
add optional timeout parameter to SSHClient.connect(), based on a patch from james bardin.
Diffstat (limited to 'paramiko')
-rw-r--r--paramiko/client.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/paramiko/client.py b/paramiko/client.py
index b6ef1833..1a4582e8 100644
--- a/paramiko/client.py
+++ b/paramiko/client.py
@@ -23,6 +23,7 @@ L{SSHClient}.
from binascii import hexlify
import getpass
import os
+import socket
from paramiko.agent import Agent
from paramiko.common import *
@@ -212,7 +213,7 @@ class SSHClient (object):
self._policy = policy
def connect(self, hostname, port=22, username=None, password=None, pkey=None,
- key_filename=None):
+ key_filename=None, timeout=None):
"""
Connect to an SSH server and authenticate to it. The server's host key
is checked against the system host keys (see L{load_system_host_keys})
@@ -246,6 +247,8 @@ class SSHClient (object):
@param key_filename: the filename of an optional private key to use
for authentication
@type key_filename: str
+ @param timeout: an optional timeout (in seconds) for the TCP connect
+ @type timeout: float
@raise BadHostKeyException: if the server's host key could not be
verified
@@ -253,7 +256,16 @@ class SSHClient (object):
@raise SSHException: if there was any other error connecting or
establishing an SSH session
"""
- t = self._transport = Transport((hostname, port))
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ if timeout is not None:
+ try:
+ sock.settimeout(timeout)
+ except:
+ pass
+
+ sock.connect((hostname, port))
+ t = self._transport = Transport(sock)
+
if self._log_channel is not None:
t.set_log_channel(self._log_channel)
t.start_client()