Permalink
Browse files

pipe() and update the example to just be an echo server

  • Loading branch information...
1 parent d653d31 commit ade87756feea0bf6d33156082c02a6ff40a87f4a @substack committed Mar 20, 2011
Showing with 20 additions and 4 deletions.
  1. +4 −2 README.markdown
  2. +1 −2 examples/shell.js
  3. +15 −0 index.js
View
@@ -6,16 +6,18 @@ Create ssh servers in node.js!
example
=======
+simple echo shell
+-----------------
+
var ssh = require('ssh');
- var repl = require('repl');
ssh.createServer(function (session) {
session.on('password', function (user, pass, cb) {
cb(user === 'foo' && pass === 'bar');
});
session.on('shell', function (sh) {
- repl.start('node-ssh $ ', sh);
+ sh.pipe(sh); // echo on
});
}).listen(2222);
View
@@ -1,12 +1,11 @@
var ssh = require('ssh');
-var repl = require('repl');
ssh.createServer(function (session) {
session.on('password', function (user, pass, cb) {
cb(user === 'foo' && pass === 'bar');
});
session.on('shell', function (sh) {
- repl.start('node-ssh $ ', sh);
+ sh.pipe(sh); // echo on
});
}).listen(2222);
View
@@ -82,6 +82,7 @@ function wrapSession (session) {
chan.pause = function () {
// TODO
};
+
chan.resume = function () {
// TODO
};
@@ -97,6 +98,20 @@ function wrapSession (session) {
throw new TypeError('can only write strings and Buffers');
}
};
+
+ chan.pipe = function (stream, opts) {
+ if (!opts) opts = {};
+
+ chan.on('data', function (buf) {
+ stream.write(buf);
+ });
+
+ if (opts.end !== false) {
+ chan.on('end', function () {
+ stream.end();
+ });
+ }
+ };
}
else if (chan
&& m.type === constants.SSH_REQUEST_CHANNEL

0 comments on commit ade8775

Please sign in to comment.