2

I'm using the Granados SSH Library and I'm trying to forward port 3306 on my localhost to port 3306 on the remote host (i.e. the MySQL server port). That is, I want to be able to make connections to the remote host's MySQL server through the SSH tunnel.

Here is an example of what I've currently tried using the Granada .NET SSH library but which doesn't seem to work:

public SSHConnection _conn;
_conn.ListenForwardedPort("localhost", 3306); //doesn't work

Can somebody please tell me how I can achieve what I want?

sversch
  • 856
  • 8
  • 22

1 Answers1

2

You have your terminology backwards! What you are trying to do is tunnel from the local machine to the remote system. This is because the remote system is the TCP server so a connection is initiated on your local system and accepted on the remote system. The ListenForwardedPort method is for the other direction.

I didn't test this but from my read of the Granados source code I think you want the ForwardPort method instead. It takes four host-related arguments like this:

  • remote_host: the host with the server on it, i.e. your MySQL server
  • remote_port: the port the server is listening on, i.e. 3306
  • originator_host: the host you want to listen on the local side, probably "localhost"
  • originator_port: the port of the host you want to connect to on the local side, you can re-use 3306 or pick any other available number

Your MySQL server, the remote_host, might be "localhost" (as seen by the other endpoint of the SSH connection) but it could also be any machine reachable by the remote system. You can also use the IP address of the remote system, i.e. something other than localhost or 127.0.0.1.

Rick Sladkey
  • 33,988
  • 6
  • 71
  • 95