Mocha测试使用SSH访问远程服务器

问题描述

我需要从mocha测试用例中使用SSH连接到远程服务器并读取文件

我尝试使用npm的ssh2库和以下代码来确认是否连接了远程服务器。但是也没有错误或没有结果。

var Client = require('ssh2').Client;
 
var conn = new Client();
conn.on('ready',function() {
  console.log('Client :: ready');
  conn.exec('uptime',function(err,stream) {
    if (err) throw err;
    stream.on('close',function(code,signal) {
      console.log('Stream :: close :: code: ' + code + ',signal: ' + signal);
      conn.end();
    }).on('data',function(data) {
      console.log('STDOUT: ' + data);
    }).stderr.on('data',function(data) {
      console.log('STDERR: ' + data);
    });
  });
}).connect({
  host: 'X.X.X.X',port: 22,username: 'frylock',password: 'xxxxxxxx'
});

请让我们知道这里遗漏了什么,并且可以从Mocha测试用例连接到SSH服务器

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)