Пример #1
0
 def __init__(self,
              host,
              username=None,
              password=None,
              private_key=None,
              private_key_pass=None,
              compress=False,
              port=22,
              timeout=30):
     self._host = host
     self._port = port
     self._pkey = None
     self._username = username or os.environ['LOGNAME']
     self._password = password
     self._timeout = timeout
     self._sftp = None
     self._scp = None
     self._transport = None
     self._progress_bar = None
     self._compress = compress
     if private_key:
         self._pkey = self.load_private_key(private_key, private_key_pass)
     elif not password:
         raise exception.SSHNoCredentialsError()
     self._glob = SSHGlob(self)
     self.__last_status = None
     atexit.register(self.close)
Пример #2
0
 def __init__(self,
              host,
              username=None,
              password=None,
              private_key=None,
              private_key_pass=None,
              port=22,
              timeout=30):
     self._timeout = timeout
     self._sftp_live = False
     self._sftp = None
     self._pkey = None
     if not username:
         username = os.environ['LOGNAME']
     # Begin the SSH transport.
     self._transport_live = False
     try:
         sock = self._get_socket(host, port)
         self._transport = paramiko.Transport(sock)
         self._transport.banner_timeout = self._timeout
     except socket.error:
         raise exception.SSHConnectionError(host, port)
     self._transport_live = True
     # Authenticate the transport.
     pkey = None
     if private_key:
         # Use Private Key.
         log.debug('private key specified')
         if private_key.endswith('rsa') or private_key.count('rsa'):
             pkey = self._load_rsa_key(private_key, private_key_pass)
         elif private_key.endswith('dsa') or private_key.count('dsa'):
             pkey = self._load_dsa_key(private_key, private_key_pass)
         else:
             log.debug("specified key does not end in either rsa or dsa" + \
                       ", trying both")
             pkey = self._load_rsa_key(private_key, private_key_pass)
             if pkey is None:
                 pkey = self._load_dsa_key(private_key, private_key_pass)
         self._pkey = pkey
     elif not password:
         raise exception.SSHNoCredentialsError()
     try:
         self._transport.connect(username=username,
                                 pkey=pkey,
                                 password=password)
     except paramiko.AuthenticationException:
         raise exception.SSHAuthException(username, host)
     except paramiko.SSHException, e:
         msg = e.args[0]
         raise exception.SSHError(msg)
Пример #3
0
 def __init__(self,
              host,
              username=None,
              password=None,
              private_key=None,
              private_key_pass=None,
              port=22,
              timeout=30):
     self._host = host
     self._port = 22
     self._pkey = None
     self._username = username or os.environ['LOGNAME']
     self._password = password
     self._timeout = timeout
     self._sftp = None
     self._transport = None
     if private_key:
         self._pkey = self.load_private_key(private_key, private_key_pass)
     elif not password:
         raise exception.SSHNoCredentialsError()