From 6539601a16b36113a73d68e319b7f1475354c3ed Mon Sep 17 00:00:00 2001 From: Peter de Croos Date: Fri, 19 Sep 2014 14:56:48 -0700 Subject: [PATCH] update readme code samples should be in main readme. Less work to find basic starting info. --- readme.txt | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index 59644a7..04458c0 100644 --- a/readme.txt +++ b/readme.txt @@ -13,6 +13,36 @@ have this installed. This will not work with windows machines. How to use ------------------------------------------------------------------------ -Check out the file "sample.js". It should help show you all you need ;) +Here's an example usage. A better version with node-expect is in betterSample.js +```javascript + +var SSHClient = require("NodeSSH"); + +var ssh=new SSHClient(addresses,user,password); +var cmds=["uptime","logout"]; +function close(addr) { + console.log('('+addresses.length+') Disconnected from '+addr); +} + +function data(buffer) { + s=buffer.toString(); + if (/\$ /.test(s)) { + if (cmd=cmds.shift()) + ssh.write(cmd+"\r\n"); + else ssh.close(); + } +} + +function connect() { + console.log('Connected to '+this.address); + this.on('data',data); +} + +ssh.on('close',close); + + +ssh.connect(connect); + +```