summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--paramiko/client.py10
-rw-r--r--paramiko/transport.py14
-rw-r--r--setup.py2
3 files changed, 20 insertions, 6 deletions
diff --git a/paramiko/client.py b/paramiko/client.py
index c4cf6964..4a65477d 100644
--- a/paramiko/client.py
+++ b/paramiko/client.py
@@ -123,6 +123,7 @@ class SSHClient (object):
self._log_channel = None
self._policy = RejectPolicy()
self._transport = None
+ self._agent = None
def load_system_host_keys(self, filename=None):
"""
@@ -339,6 +340,10 @@ class SSHClient (object):
self._transport.close()
self._transport = None
+ if self._agent != None:
+ self._agent.close()
+ self._agent = None
+
def exec_command(self, command, bufsize=-1):
"""
Execute a command on the SSH server. A new L{Channel} is opened and
@@ -436,7 +441,10 @@ class SSHClient (object):
saved_exception = e
if allow_agent:
- for key in Agent().get_keys():
+ if self._agent == None:
+ self._agent = Agent()
+
+ for key in self._agent.get_keys():
try:
self._log(DEBUG, 'Trying SSH agent key %s' % hexlify(key.get_fingerprint()))
self._transport.auth_publickey(username, key)
diff --git a/paramiko/transport.py b/paramiko/transport.py
index edca0cca..e04db26a 100644
--- a/paramiko/transport.py
+++ b/paramiko/transport.py
@@ -285,15 +285,21 @@ class Transport (threading.Thread):
if type(sock) is tuple:
# connect to the given (host, port)
hostname, port = sock
+ reason = 'No suitable address family'
for (family, socktype, proto, canonname, sockaddr) in socket.getaddrinfo(hostname, port, socket.AF_UNSPEC, socket.SOCK_STREAM):
if socktype == socket.SOCK_STREAM:
af = family
addr = sockaddr
- break
+ sock = socket.socket(af, socket.SOCK_STREAM)
+ try:
+ sock.connect((hostname, port))
+ except socket.error, e:
+ reason = str(e)
+ else:
+ break
else:
- raise SSHException('No suitable address family for %s' % hostname)
- sock = socket.socket(af, socket.SOCK_STREAM)
- sock.connect((hostname, port))
+ raise SSHException(
+ 'Unable to connect to %s: %s' % (hostname, reason))
# okay, normal socket-ish flow here...
threading.Thread.__init__(self)
self.setDaemon(True)
diff --git a/setup.py b/setup.py
index 965906f3..53cbf695 100644
--- a/setup.py
+++ b/setup.py
@@ -36,7 +36,7 @@ import sys
try:
from setuptools import setup
kw = {
- 'install_requires': 'pycrypto >= 1.9',
+ 'install_requires': 'pycrypto >= 2.1',
}
except ImportError:
from distutils.core import setup