Guest User

Untitled

a guest
Dec 10th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. var Client = require('ssh2').Client;
  2. var readline = require('readline')
  3.  
  4. var conn = new Client();
  5. conn.on('ready', function() {
  6. console.log('Client :: ready');
  7. conn.shell(function(err, stream) {
  8. if (err) throw err;
  9. // create readline interface
  10. var rl = readline.createInterface(process.stdin, process.stdout)
  11.  
  12. stream.on('close', function() {
  13. process.stdout.write('Connection closed.')
  14. console.log('Stream :: close');
  15. conn.end();
  16. }).on('data', function(data) {
  17. // pause to prevent more data from coming in
  18. process.stdin.pause()
  19. process.stdout.write('DATA: ' + data)
  20. process.stdin.resume()
  21. }).stderr.on('data', function(data) {
  22. process.stderr.write(data);
  23. });
  24.  
  25. rl.on('line', function (d) {
  26. // send data to through the client to the host
  27. stream.write(d.trim() + 'n')
  28. })
  29.  
  30. rl.on('SIGINT', function () {
  31. // stop input
  32. process.stdin.pause()
  33. process.stdout.write('nEnding sessionn')
  34. rl.close()
  35.  
  36. // close connection
  37. stream.end('exitn')
  38. })
  39.  
  40. });
  41. }).connect({
  42. host: 'www58.lan',
  43. port: 22,
  44. username: 'gorod',
  45. password: '123qwe'
  46. });
  47.  
  48. gorod@www58:~$ ls
  49. ls
  50. adil_local_for_drugmaster.sql sber-marketing sm_www94
  51. a.out sm_dev1017 System Volume Information
  52. dump20180801 sm_qa1017 www58_sm_2310
  53. dumps sm_www58
  54. gorod@www58:~$
  55.  
  56. gorod@www58:~$ ls
  57. adil_local_for_drugmaster.sql sber-marketing sm_www94
  58. a.out sm_dev1017 System Volume Information
  59. dump20180801 sm_qa1017 www58_sm_2310
  60. dumps sm_www58
  61. gorod@www58:~$
Add Comment
Please, Sign In to add comment