当前位置: 首页>>代码示例>>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;未经允许,请勿转载。