1

I am using the tunnel-ssh module to establish connection to the remote mysql database using node.js. The documentation is poor and I am not able to establish a connection. Here is the code snippet:

var tunnel = require('tunnel-ssh')
var server = tunnel.tunnel(config.sshData, function(err, result) {console.log('connected'});

Here is my sshData object.

config.sshData = {host : 'serverxyz.web-hosting.com', username : 'xyz', password : 'xyz',
srcPort: 3307, dstPort : 21098}

The dstPort is 21098 as suggested by the namecheap documentation.

However I am getting timeout error and whenever I add this snippet:

server.on('error', function(err) {});

I get the error server.on is not a function. The remote connection is working fine on putty and SQLyog. Any procedure on how to establish successful connection would be of great help. Thanks!

Update

Got the database working by using the correct ports specified and by directly using ssh2 module with the code example given here

2
  • I think that dstPort is the port your DB is available on. So if the DB is running on localhost:3307 then use dstPort: 3307 Commented Apr 13, 2016 at 9:44
  • I've used the correct port number as specified by the answer, still getting timeout error Commented Apr 13, 2016 at 11:39

1 Answer 1

1

There is a misunderstanding with the namecheap documentation. 21098 is the ssh port, not the port the database is listening on. In order to use a non-standard ssh port, you will need to explicitly specify the port value like:

config.sshData = {
  host: 'serverxyz.web-hosting.com',
  port: 21098,
  username: 'xyz',
  password: 'xyz',
  dstPort: 3306
};

Then you should be able to connect to localhost:3306 to access your remote database.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your reply. I am getting a timeout error even if use the correct port as specified. events.js:141 throw er; // Unhandled 'error' event ^ Error: Timed out while waiting for handshake at null._onTimeout (..\node_modules\tunnel-ssh\node_modules\ssh2\lib\client.js:569:19) at Timer.listOnTimeout (timers.js:92:15)
I'm able to connect to the remote host and execute uptime as mentioned here. Any ideas on how to proceed would be of great help!
I got the db working from your code given at (github.com/mscdex/ssh2/issues/351)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.