Permalink
Browse files

readme: add connection hopping example

  • Loading branch information...
1 parent 9fd2ed2 commit 80f18e2cf1e3a5f72579d4d424df9758baf4ce47 @mscdex committed Mar 4, 2014
Showing with 39 additions and 0 deletions.
  1. +39 −0 README.md
View
@@ -309,6 +309,44 @@ c.connect({
// SFTP :: SFTP session closed
```
+* Connection hopping:
+
+```javascript
+var Connection = require('ssh2');
+
+var conn1 = new Connection(),
+ conn2 = new Connection();
+
+conn1.on('ready', function() {
+ console.log('FIRST :: connection ready');
+ conn1.exec('nc 192.168.1.2 22', function(err, stream) {
+ if (err) return console.log('FIRST :: exec error: ' + err);
+ conn2.connect({
+ sock: stream,
+ username: 'user2',
+ password: 'password2',
+ });
+ });
+});
+conn1.connect({
+ host: '192.168.1.1',
+ username: 'user1',
+ password: 'password1',
+});
+
+conn2.on('ready', function() {
+ console.log('SECOND :: connection ready');
+ conn2.exec('uptime', function(err, stream) {
+ if (err) return console.log('SECOND :: exec error: ' + err);
+ stream.on('data', function(data) {
+ console.log(data.toString());
+ }).on('end', function() {
+ conn1.end(); // close parent (and this) connection
+ });
+ });
+});
+```
+
* Invoke an arbitrary subsystem (netconf in this example):
```javascript
@@ -351,6 +389,7 @@ c.connect({
});
```
+
API
===

0 comments on commit 80f18e2

Please sign in to comment.