0

I am currently using ssh2-sftp-client library to connect with sftp but I am using keyboard-interactive on method to resolve one issue I need to return the resolve after a both connect and on method are resolved. Below is my code

    const Client = require('ssh2-sftp-client');
    const sftp = new Client();

    const connectToSFTP = config => {
      console.log(config);
      return new Promise((resolve, reject) => {
        sftp.connect({
          host: config.host,
          port,
          username: config.username,
          tryKeyboard: true
        }).then(data => {
          console.log(data);
          resolve(data);
        }).catch(err => {
          console.log(err);
          reject(err);
        });

        sftp.on('keyboard-interactive', (name, instructions, instructionsLang, prompts, finish) => {
          console.log('Connection :: keyboard-interactive');
          finish([config.password]);
        })
      });

    };

const functionOne = () => {
     return new Promise((resolve, reject) => {
            resolve('somedata');
     })
}

const functionTwo = () => {
return Promise.all(lodash.map(data, (item, item1) => {

          return connectToSFTP(item.config)
              .then(data => {
                console.log(data); //cannot see data

              }).catch(err =>{
                 console.log(err);
               })  
       })

}

functionOne()
  .then(data => {
    return functionOne();
  })
  .then(data => {
    return functionOne();
  })
  .then(data => {
    return functionOne();
  })
  .then(data => {
    console.log('second');
    return functionTwo();
  }).then(data => {
  console.log('finished');
})
  .catch(err => {
    console.log(err);

  });

After everything is finished then return resolve, how can I achieve this?

JN_newbie
  • 5,492
  • 14
  • 59
  • 97

0 Answers0