當前位置: 首頁>>代碼示例>>Python>>正文


Python endpoints.SSHCommandClientEndpoint類代碼示例

本文整理匯總了Python中twisted.conch.endpoints.SSHCommandClientEndpoint的典型用法代碼示例。如果您正苦於以下問題:Python SSHCommandClientEndpoint類的具體用法?Python SSHCommandClientEndpoint怎麽用?Python SSHCommandClientEndpoint使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了SSHCommandClientEndpoint類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create

    def create(self):
        """
        Create and return a new L{SSHCommandClientEndpoint} using the
        C{existingConnection} constructor.
        """
        factory = Factory()
        factory.protocol = Protocol
        connected = self.endpoint.connect(factory)

        # Please, let me in.  This kinda sucks.
        channelLookup = self.realm.channelLookup.copy()
        try:
            self.realm.channelLookup[b'session'] = WorkingExecSession

            server, client, pump = self.connectedServerAndClient(
                self.factory, self.reactor.tcpClients[0][2])

        finally:
            self.realm.channelLookup.clear()
            self.realm.channelLookup.update(channelLookup)

        self._server = server
        self._client = client
        self._pump = pump

        protocol = self.successResultOf(connected)
        connection = protocol.transport.conn
        return SSHCommandClientEndpoint.existingConnection(
            connection, b"/bin/ls -l")
開發者ID:AlexanderHerlan,項目名稱:syncpy,代碼行數:29,代碼來源:test_endpoints.py

示例2: main

def main(reactor):
    ep = SSHCommandClientEndpoint.newConnection(
        reactor, b'/bin/cat',
        details['USER'],
        details['HOST'],
        port=details['PORT'],
        password=details['PASSWORD'],
        agentEndpoint=None,
        knownHosts=None)
    factory = Factory()
    factory.protocol = MyProtocol

    d = ep.connect(factory)


    def gotConnection(proto):
        # stdio interface
        stdio_proto = StdinProto(proto.transport.conn)
        stdio.StandardIO(stdio_proto)

        # factory = Factory()
        # factory.protocol = MyProtocol

        # e = SSHCommandClientEndpoint.existingConnection(conn, b"/bin/echo hey")
        # return e.connect(factory).addCallback(lambda proto: proto.finished)
        return stdio_proto.finished

    return d.addCallback(gotConnection)
開發者ID:moldit,項目名稱:mold,代碼行數:28,代碼來源:ssh2.py

示例3: spawnProcess

 def spawnProcess(self, protocol, command):
     factory = Factory()
     factory.protocol = lambda: _CommandProtocol(protocol)
     e = SSHCommandClientEndpoint.existingConnection(
             self.master_proto.transport.conn, command)
     d = e.connect(factory)
     return d.addCallback(self._commandStarted)
開發者ID:moldit,項目名稱:mold,代碼行數:7,代碼來源:ssh.py

示例4: connect

def connect(sdata, command, username, host, port=22, key_file=None, password=None):
    """
    Connect to an SSH host (as it happens, persistently).
    """
    sdata.set_conn_state('connecting')

    try:
        keys = [Key.fromFile(key_file)] if key_file else None
    except exceptions.IOError as e:
        print('### key load error:', str(e))
        push_failure_message(str(e), sdata)
        return

    endpoint = SSHCommandClientEndpoint.newConnection(
                    reactor, command, username, host, port=int(port),
                    keys=keys, password=password, ui=None,
                    knownHosts=PermissiveKnownHosts())

    factory = Factory()
    factory.protocol = LineProtocol
    factory.sdata = sdata

    d = endpoint.connect(factory)

    # Very small race condition between here and the replacement
    # in connectionMade() above, but I've never managed to hit it.
    def disconnect():
        sdata.log('Disconnecting while still attempting to connect, by request')
        d.cancel()
    sdata.transport_drop_cb = disconnect

    d.addErrback(lambda reason: push_failure_message(reason, sdata))
    return d
開發者ID:cisco,項目名稱:xr-telemetry-m2m-web,代碼行數:33,代碼來源:ssh.py

示例5: test_mismatchedHostKey

    def test_mismatchedHostKey(self):
        """
        If the SSH public key presented by the SSH server does not match the
        previously remembered key, as reported by the L{KnownHostsFile}
        instance use to construct the endpoint, for that server, the
        L{Deferred} returned by L{SSHCommandClientEndpoint.connect} fires with
        a L{Failure} wrapping L{HostKeyChanged}.
        """
        differentKey = Key.fromString(privateDSA_openssh).public()
        knownHosts = KnownHostsFile(self.mktemp())
        knownHosts.addHostKey(self.serverAddress.host, differentKey)
        knownHosts.addHostKey(self.hostname, differentKey)

        # The UI may answer true to any questions asked of it; they should
        # make no difference, since a *mismatched* key is not even optionally
        # allowed to complete a connection.
        ui = FixedResponseUI(True)

        endpoint = SSHCommandClientEndpoint.newConnection(
            self.reactor, b"/bin/ls -l", b"dummy user",
            self.hostname, self.port, password=b"dummy password",
            knownHosts=knownHosts, ui=ui)

        factory = Factory()
        factory.protocol = Protocol
        connected = endpoint.connect(factory)

        server, client, pump = self.connectedServerAndClient(
            self.factory, self.reactor.tcpClients[0][2])

        f = self.failureResultOf(connected)
        f.trap(HostKeyChanged)
開發者ID:AlexanderHerlan,項目名稱:syncpy,代碼行數:32,代碼來源:test_endpoints.py

示例6: execute

    def execute(self):
        """Execute the CLI command"""

        cmd = " ".join(self.cmd)
        LOGGER.debug('Executing {0}'.format(cmd))
        endpoint = SSHCommandClientEndpoint.newConnection(reactor,
            b"{0}".format(cmd), self.config.get('username'),
            self.config.get('host'),
            port=self.config.get('port', 22),
            password=self.config.get('passsword'),
            agentEndpoint=self.agent_endpoint,
            keys=self.keys,
            knownHosts=self.known_hosts)
        factory = protocol.Factory()
        factory.protocol = AsteriskRemoteProtocol

        def _nominal(param):
            self.exitcode = 0
            self.output = param.output
            self.err = self.output
            LOGGER.debug('Remote Asterisk process completed successfully')
            return self

        def _error(param):
            self.exitcode = -1
            self.output = param.value.output
            self.err = self.output
            LOGGER.warning('Remote Asterisk process failed: {0}'.format(self.err))
            return Failure(self)

        deferred = endpoint.connect(factory)
        deferred.addCallback(lambda proto: proto.finished)
        deferred.addCallbacks(_nominal, _error)
        return deferred
開發者ID:colinsung,項目名稱:testsuite,代碼行數:34,代碼來源:asterisk.py

示例7: test_connectionCancelledBeforeSecure

    def test_connectionCancelledBeforeSecure(self):
        """
        If the connection is cancelled before the SSH transport layer has
        finished key exchange (ie, gotten to the point where we may attempt to
        authenticate), the L{Deferred} returned by
        L{SSHCommandClientEndpoint.connect} fires with a L{Failure} wrapping
        L{CancelledError} and the connection is aborted.
        """
        endpoint = SSHCommandClientEndpoint.newConnection(
            self.reactor, b"/bin/ls -l", b"dummy user",
            self.hostname, self.port, knownHosts=self.knownHosts,
            ui=FixedResponseUI(False))

        factory = Factory()
        factory.protocol = Protocol
        d = endpoint.connect(factory)

        transport = AbortableFakeTransport(None, isServer=False)
        factory = self.reactor.tcpClients[0][2]
        client = factory.buildProtocol(None)
        client.makeConnection(transport)
        d.cancel()

        self.failureResultOf(d).trap(CancelledError)
        self.assertTrue(transport.aborted)
        # Make sure the connection closing doesn't result in unexpected
        # behavior when due to cancellation:
        client.connectionLost(Failure(ConnectionDone()))
開發者ID:AlexanderHerlan,項目名稱:syncpy,代碼行數:28,代碼來源:test_endpoints.py

示例8: test_passwordAuthenticationFailure

    def test_passwordAuthenticationFailure(self):
        """
        If the SSH server rejects the password presented during authentication,
        the L{Deferred} returned by L{SSHCommandClientEndpoint.connect} fires
        with a L{Failure} wrapping L{AuthenticationFailed}.
        """
        endpoint = SSHCommandClientEndpoint.newConnection(
            self.reactor, b"/bin/ls -l", b"dummy user",
            self.hostname, self.port,  password=b"dummy password",
            knownHosts=self.knownHosts, ui=FixedResponseUI(False))

        factory = Factory()
        factory.protocol = Protocol
        connected = endpoint.connect(factory)

        server, client, pump = self.connectedServerAndClient(
            self.factory, self.reactor.tcpClients[0][2])

        # For security, the server delays password authentication failure
        # response.  Advance the simulation clock so the client sees the
        # failure.
        self.reactor.advance(server.service.passwordDelay)

        # Let the failure response traverse the "network"
        pump.flush()

        f = self.failureResultOf(connected)
        f.trap(AuthenticationFailed)
        # XXX Should assert something specific about the arguments of the
        # exception

        self.assertClientTransportState(client, False)
開發者ID:AlexanderHerlan,項目名稱:syncpy,代碼行數:32,代碼來源:test_endpoints.py

示例9: _get_endpoint

 def _get_endpoint(self):
     """ Creates a generic endpoint connection that doesn't finish
     """
     return SSHCommandClientEndpoint.newConnection(
         reactor, b'/bin/cat', self.username, self.hostname,
         port=self.port, keys=self.keys, password=self.password,
         knownHosts = self.knownHosts)
開發者ID:calston,項目名稱:tensor,代碼行數:7,代碼來源:ssh.py

示例10: test_publicKeyAuthenticationFailure

    def test_publicKeyAuthenticationFailure(self):
        """
        If the SSH server rejects the key pair presented during authentication,
        the L{Deferred} returned by L{SSHCommandClientEndpoint.connect} fires
        with a L{Failure} wrapping L{AuthenticationFailed}.
        """
        badKey = Key.fromString(privateRSA_openssh)
        self.setupKeyChecker(self.portal, {self.user: privateDSA_openssh})

        endpoint = SSHCommandClientEndpoint.newConnection(
            self.reactor, b"/bin/ls -l", self.user,
            self.hostname, self.port, keys=[badKey],
            knownHosts=self.knownHosts, ui=FixedResponseUI(False))

        factory = Factory()
        factory.protocol = Protocol
        connected = endpoint.connect(factory)

        server, client, pump = self.connectedServerAndClient(
            self.factory, self.reactor.tcpClients[0][2])

        f = self.failureResultOf(connected)
        f.trap(AuthenticationFailed)
        # XXX Should assert something specific about the arguments of the
        # exception

        # Nothing useful can be done with the connection at this point, so the
        # endpoint should close it.
        self.assertTrue(client.transport.disconnecting)
開發者ID:AlexanderHerlan,項目名稱:syncpy,代碼行數:29,代碼來源:test_endpoints.py

示例11: executeNewCommand

    def executeNewCommand(self, line):
        factory = Factory()
        factory.protocol = MyProtocol

        e = SSHCommandClientEndpoint.existingConnection(self.ssh_conn,
                                                        line.strip())
        d = e.connect(factory)
        d.addCallback(self.protoStarted)
開發者ID:moldit,項目名稱:mold,代碼行數:8,代碼來源:ssh2.py

示例12: test_interface

 def test_interface(self):
     """
     L{SSHCommandClientEndpoint} instances provide L{IStreamClientEndpoint}.
     """
     endpoint = SSHCommandClientEndpoint.newConnection(
         self.reactor, b"dummy command", b"dummy user",
         self.hostname, self.port)
     self.assertTrue(verifyObject(IStreamClientEndpoint, endpoint))
開發者ID:AlexanderHerlan,項目名稱:syncpy,代碼行數:8,代碼來源:test_endpoints.py

示例13: exec_command

    def exec_command(self, command):
        conn = self.transport.conn
        factory = protocol.Factory()
        factory.protocol = SingleCommandProtocol

        e = SSHCommandClientEndpoint.existingConnection(conn, command)
        d = e.connect(factory)
        d.addCallback(lambda p: p.finished)
        return d
開發者ID:GaretJax,項目名稱:ipd,代碼行數:9,代碼來源:ssh.py

示例14: _endpoint_for_command

 def _endpoint_for_command(self, command):
     return SSHCommandClientEndpoint.newConnection(
         self.reactor, command, self.username, self.host,
         port=self.port,
         password=self.password,
         keys=self.keys,
         agentEndpoint=self.agent,
         knownHosts=self.knownHosts,
         ui=self.ui
     )
開發者ID:gcgirish-radisys,項目名稱:voltha,代碼行數:10,代碼來源:rcmd.py

示例15: connectionMade

 def connectionMade(self):
     script_dir = os.getcwd()
     rel_path = "hostkeys"
     abs_file_path = os.path.join(script_dir, rel_path)
     knownHosts = KnownHostsFile.fromPath(abs_file_path)
     self.point = SSHCommandClientEndpoint.newConnection(reactor, 'cmd', 'user', '127.0.0.1', port=5122,
                                                         password='password', knownHosts=PermissiveKnownHosts())
     self.sshSide = FzSSHClient()
     self.sshSide.tcpSide = self
     connectProtocol(self.point, self.sshSide)
開發者ID:matanmaz,項目名稱:SshTelnetProxy,代碼行數:10,代碼來源:TcpSshConverter.py


注:本文中的twisted.conch.endpoints.SSHCommandClientEndpoint類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。