Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Client = require('ssh2').Client;
- var readline = require('readline')
- var conn = new Client();
- conn.on('ready', function() {
- console.log('Client :: ready');
- conn.shell(function(err, stream) {
- if (err) throw err;
- // create readline interface
- var rl = readline.createInterface(process.stdin, process.stdout)
- stream.on('close', function() {
- process.stdout.write('Connection closed.')
- console.log('Stream :: close');
- conn.end();
- }).on('data', function(data) {
- // pause to prevent more data from coming in
- process.stdin.pause()
- process.stdout.write('DATA: ' + data)
- process.stdin.resume()
- }).stderr.on('data', function(data) {
- process.stderr.write(data);
- });
- rl.on('line', function (d) {
- // send data to through the client to the host
- stream.write(d.trim() + 'n')
- })
- rl.on('SIGINT', function () {
- // stop input
- process.stdin.pause()
- process.stdout.write('nEnding sessionn')
- rl.close()
- // close connection
- stream.end('exitn')
- })
- });
- }).connect({
- host: 'www58.lan',
- port: 22,
- username: 'gorod',
- password: '123qwe'
- });
- gorod@www58:~$ ls
- ls
- adil_local_for_drugmaster.sql sber-marketing sm_www94
- a.out sm_dev1017 System Volume Information
- dump20180801 sm_qa1017 www58_sm_2310
- dumps sm_www58
- gorod@www58:~$
- gorod@www58:~$ ls
- adil_local_for_drugmaster.sql sber-marketing sm_www94
- a.out sm_dev1017 System Volume Information
- dump20180801 sm_qa1017 www58_sm_2310
- dumps sm_www58
- gorod@www58:~$
Add Comment
Please, Sign In to add comment