Skip to content

Instantly share code, notes, and snippets.

@nullivex
Created August 25, 2014 21:36
Show Gist options
  • Save nullivex/26fd27cfb378d20d7ff8 to your computer and use it in GitHub Desktop.
Save nullivex/26fd27cfb378d20d7ff8 to your computer and use it in GitHub Desktop.
Proper streaming from SSH2 on Node
'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