-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.js
More file actions
48 lines (44 loc) · 1.28 KB
/
Copy pathdeploy.js
File metadata and controls
48 lines (44 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* eslint-disable no-console */
/**
* ./config/ftp.config.js looks like this:
* exports.ftpCredentials = {
* username: 'USERNAME',
* password: '**********',
* host: 'HOSTURL or IP',
* port: 21,
* };
*/
const SftpClient = require('ssh2-sftp-client');
const path = require('path');
const { ftpCredentials } = require('./config/ftp.config');
async function main() {
const client = new SftpClient('upload-test');
const localRoot = path.join(__dirname, 'build');
const remoteRoot = '/petition.klima-mitbestimmung.jetzt/';
const remoteDest = `${remoteRoot}httpdocs/`;
const remoteTemp = `${remoteRoot}temp/`;
client.on('upload', (info) => {
console.log(`Uploaded ${info.source}`);
});
try {
await client.connect(ftpCredentials);
await client.mkdir(remoteTemp, true);
const rslt = await client.uploadDir(localRoot, remoteTemp);
try {
await client.rmdir(remoteDest, true);
} catch (err) {
console.error(err.message);
}
await client.rename(remoteTemp, remoteDest);
return rslt;
} finally {
client.end();
}
}
main()
.then((msg) => {
console.log(msg);
})
.catch((err) => {
console.log(`main error: ${err.message}`);
});