mirror of
https://github.com/tcgdex/compiler.git
synced 2025-04-22 10:42:09 +00:00
38 lines
810 B
JavaScript
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}`);
|
|
});
|