title: Using the Node module SSH2 with shell
body: <p>My aim is to make a web application that allows it's user to connect to an SSH server remotely, i.e. without installing an SSH client on their computer. So this means my server will be an intermediate interface between the user and their SSH server/s.</p>
  
  <p>I found an SSH2 module for node: <a href="https://github.com/mscdex/ssh2" rel="nofollow">https://github.com/mscdex/ssh2</a></p>
  
  <p>I figured the most appropriate method of connecting was using the <code>shell()</code> method.</p>
  
  <p>The following is a basic attempt to get a shell working.</p>
  
  <pre><code>var Connection = require('ssh2');
  
  var c = new Connection();
  
  c.on('ready', function() {
     c.shell(onShell);
  });
  
  var onShell = function(err, stream) { 
      if (err != null) {
          console.log('error: ' + err);
      }
  
      stream.on('readable', function() {
          var chunk;
          while (null !== (chunk = stream.read())) {
              console.log('got %d bytes of data', chunk.length);
          }
      });
  
      stream.write('ls\r\n');
  
      console.log('Shell');
  
  }
  
  c.connect({
      host: 'localhost',
      port: 22, 
      username: 'matt',
      password: 'password'
  });
  </code></pre>
  
  <p>It connects fine, and there are no errors, but the "got %d bytes of data" does not show. How can I fix this?</p>
  
  <p>Furthermore would this method be sensible in a large scale application with potentially many simultaneous different connections?</p>