NodeJS Extension for SSH & SFTP

The package you’re using for SSH might not facilitate doing this:

  • Make stdout available as output inside Wappler

It seems to use a callback instead of the more modern promise or async/await syntax, modern example here:

await ssh.connect();
let output = await ssh.exec("whoami");
console.log(output); // Log to console as currently doing
return {output: output} // Returns object to Wappler, with element "output"
/*
{
    "output": "root"
}
*/

In addition to the output string, the object may contain the exit code of the command - this is why I’m not returning a string directly, but instead wrapping it in an object. An exit code of 0 indicates the command was successful

I highly recommend the usage of the async/await syntax, see here to convert your .js extension code for usage with async/await:

You’d then need to swap the NPM package you’re using for one with first-hand support for promises/async-await, like the one linked above. Anything that supports Promises supports Async/Await.

1 Like