本文整理汇总了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()
示例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
示例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
示例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],
)
示例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()