title: grunt.js task why not event listen?
body: <p>In order to operate the ssh on grunt plug-in, using the ssh2, I have created a task, but before the connect () later, on event occurs, the process will be terminated. What could be causing this?</p>
  
  <p>there is no problem at the normal program you do not want to use the grunt.js. . .</p>
  
  <p>Gruntfile</p>
  
  <pre><code>ssh2sample: {
          default_options: {
          options: {
          'host': 'xxx.xxx.xxx.xxx',
          'port': 22,
          'username': 'names',
          'privateKey':  'keys',
          'passphrase': 'pass'
      },
  </code></pre>
  
  <p>task/ssh2sample.js</p>
  
  <pre><code>'use strict';
  
  module.exports = function(grunt) {
  
  // Please see the Grunt documentation for more information regarding task
  // creation: http://gruntjs.com/creating-tasks
  
  grunt.registerMultiTask('ssh2sample', 'The best Grunt plugin ever.', function() {
  
  // Merge task-specific and/or target-specific options with these defaults.
  
    var Connection = require('ssh2');
  
  
    var options = this.options();
    options.privateKey = require('fs').readFileSync(options.privateKey);
  
    var c = new Connection();
  
    c.on('connect', function() {
        console.log('Connection :: connect');
    });
  
    c.on('ready', function() {
        console.log('Connection :: ready');
        c.exec('uptime', function(err, stream) {
            //if (err) throw err;
            stream.on('data', function(data, extended) {
                console.log(extended === 'stderr' ? 'STDERR: ' : 'STDOUT: '+ data);
            });
            stream.on('end', function() {
                console.log('Stream :: EOF');
            });
            stream.on('close', function() {
                console.log('Stream :: close');
            });
            stream.on('exit', function(code, signal) {
                console.log('Stream :: exit :: code: ' + code + ', signal: ' + signal);
                c.end();
            });
        });
    });
    c.on('error', function(err) {
        console.log('Connection :: error :: ' + err);
    });
    c.on('end', function() {
        console.log('Connection :: end');
    });
    c.on('close', function(had_error) {
        console.log('Connection :: close');
    });
  
    c.connect(options);
  }
  });
  </code></pre>
  
  <p>no problem ssh2connect</p>
  
  <pre><code>  var Connection = require('ssh2');
  
  
    var options = this.options();
    options.privateKey = require('fs').readFileSync(options.privateKey);
  
    var c = new Connection();
  
    c.on('connect', function() {
        console.log('Connection :: connect');
    });
  
    c.on('ready', function() {
        console.log('Connection :: ready');
        c.exec('uptime', function(err, stream) {
            //if (err) throw err;
            stream.on('data', function(data, extended) {
                console.log(extended === 'stderr' ? 'STDERR: ' : 'STDOUT: '+ data);
            });
            stream.on('end', function() {
                console.log('Stream :: EOF');
            });
            stream.on('close', function() {
                console.log('Stream :: close');
            });
            stream.on('exit', function(code, signal) {
                console.log('Stream :: exit :: code: ' + code + ', signal: ' + signal);
                c.end();
            });
        });
    });
    c.on('error', function(err) {
        console.log('Connection :: error :: ' + err);
    });
    c.on('end', function() {
        console.log('Connection :: end');
    });
    c.on('close', function(had_error) {
        console.log('Connection :: close');
    });
  
    var key = require(fs).readdirSync(keys); 
  
    c.connect({
          'host': 'xxx.xxx.xxx.xxx',
          'port': 22,
          'username': 'names',
          'privateKey':  key,
          'passphrase': 'pass'
     });
  </code></pre>