I am getting an Error: read ECONNRESET error while connecting to a sftp for a second time, first time when it is connected data is uploaded then when connection is made for a second time on a second iteration it throws an error.
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();
});
});
When it calls for a second time I am getting
{ 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' }