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


Python asyncssh.create_server方法代碼示例

本文整理匯總了Python中asyncssh.create_server方法的典型用法代碼示例。如果您正苦於以下問題:Python asyncssh.create_server方法的具體用法?Python asyncssh.create_server怎麽用?Python asyncssh.create_server使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在asyncssh的用法示例。


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

示例1: main

# 需要導入模塊: import asyncssh [as 別名]
# 或者: from asyncssh import create_server [as 別名]
def main(port=8222):
    """
    Example that starts the REPL through an SSH server.
    """
    loop = asyncio.get_event_loop()

    # Namespace exposed in the REPL.
    environ = {"hello": "world"}

    # Start SSH server.
    def create_server():
        return MySSHServer(lambda: environ)

    print("Listening on :%i" % port)
    print('To connect, do "ssh localhost -p %i"' % port)

    loop.run_until_complete(
        asyncssh.create_server(
            create_server, "", port, server_host_keys=["/etc/ssh/ssh_host_dsa_key"]
        )
    )

    # Run eventloop.
    loop.run_forever() 
開發者ID:prompt-toolkit,項目名稱:ptpython,代碼行數:26,代碼來源:asyncio-ssh-python-embed.py

示例2: __call__

# 需要導入模塊: import asyncssh [as 別名]
# 或者: from asyncssh import create_server [as 別名]
def __call__(self):
        database = Service.resolve("moxie.cores.database.DatabaseService")
        # self.alert = CronService.resolve("moxie.cores.alert.AlertService")
        # register an ssh callback for each thinger
        ssh_host_keys = asyncssh.read_private_key_list('ssh_host_keys')

        if MoxieSSHServer._keys is None:
            authorized_keys = {}
            for key in asyncssh.read_public_key_list('authorized_keys'):
                authorized_keys[key] = (yield from
                                        database.user.get_by_fingerprint(
                                            fingerprint(key)))

            MoxieSSHServer._keys = authorized_keys

        obj = yield from asyncssh.create_server(
            MoxieSSHServer, '0.0.0.0', 2222,
            server_host_keys=ssh_host_keys
        )

        return obj 
開發者ID:paultag,項目名稱:moxie,代碼行數:23,代碼來源:ssh.py

示例3: test_basic_login

# 需要導入模塊: import asyncssh [as 別名]
# 或者: from asyncssh import create_server [as 別名]
def test_basic_login(self):

    async def run_client():
      async with asyncssh.connect(
          'localhost',
          port=8888,
          username='johnny',
          password='secretpw',
          known_hosts=None) as _:
        pass

    ssh_key_file = 'ssh.key'
    SSH.generate_ssh_key(ssh_key_file)

    options = {'enabled': 'True', 'port': 8888}
    server_coro = asyncssh.create_server(
        lambda: SSH(options, self.loop),
        '0.0.0.0',
        8888,
        server_host_keys=['ssh.key'])
    self.server = self.loop.run_until_complete(server_coro)

    try:
      self.loop.run_until_complete(run_client())
    except asyncssh.misc.PermissionDenied:
      pass 
開發者ID:johnnykv,項目名稱:heralding,代碼行數:28,代碼來源:test_ssh.py

示例4: start_sftp_server

# 需要導入模塊: import asyncssh [as 別名]
# 或者: from asyncssh import create_server [as 別名]
def start_sftp_server(authorized_client_keys: str,
                            sftp_port: int,
                            server_host_keys: str,
                            server_factory: object,
                            ssh_port: int = None,
                            sftp_factory: bool or object = True,
                            **kwargs):
    '''
    Start the sftp server
    Based off of examples at https://github.com/ronf/asyncssh/tree/master/examples
    :param authorized_client_keys:
    :param port:
    :param server_host_keys:
    :param sftp_factory:
    :param kwargs:
    :return:
    '''
    await asyncssh.listen(host='',
                          port=sftp_port,
                          authorized_client_keys=authorized_client_keys,
                          server_host_keys=[server_host_keys],
                          sftp_factory=sftp_factory,
                          **kwargs)

    # 'reuse_address' probably also has to be `True` in this case
    if kwargs.get('reuse_port') and not ssh_port:
        ssh_port = sftp_port

    # Don't create the ssh server unless there is a port available for it
    if ssh_port:
        await asyncssh.create_server(
            host='',
            server_factory=server_factory,
            port=ssh_port,
            authorized_client_keys=authorized_client_keys,
            server_host_keys=[server_host_keys],
        ) 
開發者ID:saltstack,項目名稱:heist,代碼行數:39,代碼來源:sftp_server.py

示例5: main

# 需要導入模塊: import asyncssh [as 別名]
# 或者: from asyncssh import create_server [as 別名]
def main(port=8222):
    # Set up logging.
    logging.basicConfig()
    logging.getLogger().setLevel(logging.DEBUG)

    loop = asyncio.get_event_loop()
    loop.run_until_complete(
        asyncssh.create_server(
            lambda: PromptToolkitSSHServer(interact),
            "",
            port,
            server_host_keys=["/etc/ssh/ssh_host_ecdsa_key"],
        )
    )
    loop.run_forever() 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:17,代碼來源:asyncssh-server.py


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