示例#1
0
    def secureConnection(self):
        """
        Create and return a new SSH connection which has been secured and on
        which authentication has already happened.

        @return: A L{Deferred} which fires with the ready-to-use connection or
            with a failure if something prevents the connection from being
            setup, secured, or authenticated.
        """
        factory = Factory()
        factory.protocol = _CommandTransport
        factory.hostname = self.hostname
        factory.username = self.username
        factory.keys = self.keys
        factory.password = self.password
        factory.agentEndpoint = self.agentEndpoint
        factory.knownHosts = self.knownHosts
        factory.command = self.command
        factory.ui = self.ui
        factory.creator = self

        factory.connectionReady = Deferred()

        sshClient = TCP4ClientEndpoint(self.reactor, self.hostname, self.port)

        d = sshClient.connect(factory)
        d.addCallback(lambda ignored: factory.connectionReady)
        return d