def init_loopback(): global sftp, tc socks = LoopSocket() sockc = LoopSocket() sockc.link(socks) tc = paramiko.Transport(sockc) ts = paramiko.Transport(socks) host_key = paramiko.RSAKey.from_private_key_file('tests/test_rsa.key') ts.add_server_key(host_key) event = threading.Event() server = StubServer() ts.set_subsystem_handler('sftp', paramiko.SFTPServer, StubSFTPServer) ts.start_server(event, server) tc.connect(username='******', password='******') event.wait(1.0) sftp = paramiko.SFTP.from_transport(tc)
def main(): paramiko.common.logging.basicConfig(level=logging.INFO) server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True) server_socket.bind((HOST, PORT)) server_socket.listen(1) conn, addr = server_socket.accept() host_key = paramiko.RSAKey.from_private_key_file(KEYFILE) transport = paramiko.Transport(conn) transport.add_server_key(host_key) transport.set_subsystem_handler( 'sftp', paramiko.SFTPServer, StubSFTPServer) server = StubServer() transport.start_server(server=server) channel = transport.accept() while transport.is_active(): time.sleep(1)
def start_server(host, port, keyfile, level): paramiko_level = getattr(paramiko.common, level) paramiko.common.logging.basicConfig(level=paramiko_level) server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True) server_socket.bind((host, port)) server_socket.listen(BACKLOG) while True: conn, addr = server_socket.accept() host_key = paramiko.RSAKey.from_private_key_file(keyfile) transport = paramiko.Transport(conn) transport.add_server_key(host_key) transport.set_subsystem_handler('sftp', paramiko.SFTPServer, StubSFTPServer) server = StubServer() transport.start_server(server=server) channel = transport.accept() while transport.is_active(): time.sleep(1)