Open nhansendev opened 1 year ago
I figured out what I was doing wrong.
Working class example:
from pssh.clients import SSHClient
from pssh.clients.native.tunnel import TunnelServer
import threading, time
class PsshTunnel:
def __init__(self, remote_ip, username, host="localhost", port=8080):
self.remote_ip = remote_ip
self.username = username
self.host = host
self.port = port
def _run(self):
client = SSHClient(self.remote_ip, self.username)
self.serv = TunnelServer(client, self.host, self.port, bind_address=self.host)
self.serv.serve_forever()
def start(self):
self.th = threading.Thread(target=self._run, daemon=True)
self.th.start()
# Give it time to connect
time.sleep(3)
def stop(self):
self.serv.stop()
@property
def socket_port(self):
return self.serv.listen_port
Is your feature request related to a problem? Please describe. I'm trying to determine if/how parallel-ssh can be used for local port forwarding (tunneling) in a way that allows for arbitrary socket connections. The description for the Tunnel Server sounds exactly like what I need (I think), but I do not see any clear documentation/tutorials on its usage.
I've tried the following, but while the SSH client connection is accepted, the socket is rejected:
ConnectionRefusedError: [Errno 111] Connection refused
Describe the solution you'd like An example showing the correct usage of a TunnelServer for SSH local port forwarding.
Describe alternatives you've considered Using a different library, but I am not able to for my project.