xxxxxxxxxx
const fs = require('fs')
const path = require('path')
const {NodeSSH} = require('node-ssh')
const ssh = new NodeSSH()
ssh.connect({
host: 'abc123456-example.compute-1.amazonaws.com', //replace with your ec2 host
username: 'ubuntu', //replace with your EC2 username
privateKey: './yourprivatekey.pem' //replace with your private key file
})
.then(function() {
// Local, Remote (replace with you own file path)
ssh.getFile('/home/pi/test.txt', '/home/ubuntu/test.txt').then(function(Contents) {
console.log("The File's contents were successfully downloaded")
}, function(error) {
console.log("Something's wrong")
console.log(error)
})
})