compiler/upload.js
Florian Bouillon bfd0856a84
Marged some commits
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2020-03-17 14:45:08 +01:00

38 lines
810 B
JavaScript

'use strict';
// Example of using the uploadDir() method to upload a directory
// to a remote SFTP server
const path = require('path');
const SftpClient = require('ssh2-sftp-client');
const config = {
host: process.env.UPLOAD_REMOTE,
username: process.env.UPLOAD_USERNAME,
password: process.env.UPLOAD_PASSWORD ,
port: 22
};
async function main() {
const client = new SftpClient();
const src = path.join(__dirname, 'dist');
const dst = process.env.UPLOAD_DIST;
try {
await client.connect(config);
client.on('upload', info => {
console.log(`${info.source} => ${info.destination}`);
});
let rslt = await client.uploadDir(src, dst);
return rslt;
} finally {
client.end();
}
}
main().then(msg => {
console.log(msg);
}).catch(err => {
console.log(`main error: ${err.message}`);
});