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.

Revisions

  1. nullivex created this gist Aug 25, 2014.
    28 changes: 28 additions & 0 deletions stream.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    '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')
    })