const node_ssh = require('node-ssh'); const config = require('./config'); const path = require('path'); const fs = require('fs'); config.servers.forEach((host, index) => { console.log(host); let ssh = new node_ssh(); ssh.connect({ host: host, username: 'root', port: 22, password: config.password, }).then(async function() { ssh.getFile(path.resolve(__dirname, `server-${index}.log`), '/root/autoTrade/autoTrade.log') .then( function(Contents) { console.log("The File's contents were successfully downloaded"); }, function(error) { console.log("Something's wrong"); console.log(error); }, ) .then(() => { ssh.dispose(); }); }); });