Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample To Print Files In Directory Through SSH Using Node.js
const Ssh = require('node-ssh');
async function main() {
const ssh = new Ssh();
const sshPassword = 'SSH_PASSWORD';
// connect
await ssh.connect({
host: 'SSH_HOST_ADDRESS',
port: SSH_PORT,
username: 'SSH_USER_NAME',
password: sshPassword
});
// execute command
res = await ssh.execCommand('ls -al', {options: {pty: true}});
console.log(res);
// disconnect
ssh.dispose();
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment