~bialix/paramiko/paramiko.ctypes

« back to all changes in this revision

Viewing changes to paramiko/client.py

  • Committer: Alexander Belchenko
  • Date: 2007-07-26 19:13:20 UTC
  • mfrom: (434.1.9 paramiko)
  • Revision ID: bialix@ukr.net-20070726191320-00xwjpovzdw93gpm
merge latest changes from trunk (up to v.1.7.1)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Robey Pointer <robey@lag.net>
 
1
# Copyright (C) 2006-2007  Robey Pointer <robey@lag.net>
2
2
#
3
3
# This file is part of paramiko.
4
4
#
23
23
from binascii import hexlify
24
24
import getpass
25
25
import os
 
26
import socket
26
27
 
27
28
from paramiko.agent import Agent
28
29
from paramiko.common import *
212
213
        self._policy = policy
213
214
 
214
215
    def connect(self, hostname, port=22, username=None, password=None, pkey=None,
215
 
                key_filename=None):
 
216
                key_filename=None, timeout=None):
216
217
        """
217
218
        Connect to an SSH server and authenticate to it.  The server's host key
218
219
        is checked against the system host keys (see L{load_system_host_keys})
246
247
        @param key_filename: the filename of an optional private key to use
247
248
            for authentication
248
249
        @type key_filename: str
 
250
        @param timeout: an optional timeout (in seconds) for the TCP connect
 
251
        @type timeout: float
249
252
        
250
253
        @raise BadHostKeyException: if the server's host key could not be
251
254
            verified
253
256
        @raise SSHException: if there was any other error connecting or
254
257
            establishing an SSH session
255
258
        """
256
 
        t = self._transport = Transport((hostname, port))
 
259
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 
260
        if timeout is not None:
 
261
            try:
 
262
                sock.settimeout(timeout)
 
263
            except:
 
264
                pass
 
265
 
 
266
        sock.connect((hostname, port))
 
267
        t = self._transport = Transport(sock)
 
268
 
257
269
        if self._log_channel is not None:
258
270
            t.set_log_channel(self._log_channel)
259
271
        t.start_client()