3

我收到一个错误:第二次连接到 sftp 时读取 ECONNRESET 错误,第一次连接时上传数据,然后在第二次迭代中第二次建立连接时会引发错误。

const Client = require('ssh2-sftp-client');
const sftp = new Client();
const connectSFTP = config => {
  console.log(config);
  return sftp.connect({
    host: config.host,
    port,
    username: config.username,
    password: config.password
  });
  /*sftp.on('keyboard-interactive', (name, instructions, instructionsLang, prompts, finish) => {
    console.log('Connection :: keyboard-interactive');
    finish([config.password]);
  });*/
  //});
};

async.eachLimit(data, 1, (item, cb) => {
    connectSFTP(item.config)
      .then(data => {
        //return data;
        return mkdir('/somepath');
      }).then(data => {
        return sftp.put(new Buffer(item.data), '/somepath'+ '.json', true, 'utf-8');
      }).then(data => {
        console.log(data);
        console.log('end');
        return sftp.end();
      }).then(data => {
        console.log(data);
        console.log('ok')
        return cb();
      }).catch(err => {
        console.log('some error');
        console.log(err);
        sftp.end();
        return cb();
      });
  });

当它第二次呼唤我时

{ Error: read ECONNRESET
    at _errnoException (util.js:992:11)
    at TCP.onread (net.js:618:25)
  code: 'ECONNRESET',
  errno: 'ECONNRESET',
  syscall: 'read',
  level: 'client-socket' }
4

0 回答 0