Created
August 25, 2014 21:36
-
-
Save nullivex/26fd27cfb378d20d7ff8 to your computer and use it in GitHub Desktop.
Proper streaming from SSH2 on Node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var fs = require('fs') | |
var SSH = require('ssh2') | |
var conn = new SSH() | |
conn.on('ready',function(){ | |
conn.exec('cat .ssh/known_hosts',function(err,stream){ | |
stream.setEncoding('utf-8') | |
stream.on('readable',function(){ | |
console.log('stream readable') | |
console.log(stream.read()) | |
}) | |
stream.on('end',function(){ | |
console.log('called end') | |
}) | |
stream.on('close',function(){ | |
console.log('called close') | |
}) | |
stream.on('finish',function(){ | |
console.log('called finish') | |
}) | |
}) | |
}) | |
conn.connect({ | |
host: 'localhost', | |
username: 'root', | |
privateKey: fs.readFileSync('/path/to/key') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment