1

Im using the https://www.npmjs.com/package/ssh2-sftp-client library and have the following working code.

async function upload() {

    let sftp = new Client();
    await sftp.connect(config)
        .then(() => {
            return sftp.fastPut('test.txt' , 'test.txt');
        })
        .then(p => {
            console.log(`${p}`);
            return sftp.end();
        })
        .catch(err => {
            console.log(`Error: ${err.message}`); // error message will include 'example-client'
        });
}

upload()

There are two things in the docs that I don't understand.

  1. This https://www.npmjs.com/package/ssh2-sftp-client#debugging-support suggests that I can add this to my code to enable debug e.g.
config.debug = msg => {
  console.error(msg);
};

However, I can't work out where this should go.

  1. The docs also suggest https://www.npmjs.com/package/ssh2-sftp-client#uploaddirsrcdir-dstdir--string that I can add an event listener to the code to get the events. e.g.
client.on('upload', info => {
    console.log(`Listener: Uploaded ${info.source}`);
  });

However, again I can't figure where this should go.

Sorry if these dumb questions, but Async coding messes with my brain.

user1513388
  • 7,165
  • 14
  • 69
  • 111

1 Answers1

1

For debugging, you can add that to the connection config (which you don't have listed)

something like

sftp.connect({
                host: 'hostNAME',
                port: '22',
                username: "USERNAME",
                password: "PASSWORD",
                debug: console.log
            }).then(() => {
Andy P
  • 109
  • 8