Skip to content

Instantly share code, notes, and snippets.

@pirosuke
Created January 19, 2019 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pirosuke/c3da245490eb42de6c3ab344ea0cde38 to your computer and use it in GitHub Desktop.
Save pirosuke/c3da245490eb42de6c3ab344ea0cde38 to your computer and use it in GitHub Desktop.
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