-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.js
42 lines (32 loc) · 1.07 KB
/
upload.js
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
const FtpClient = require("basic-ftp");
const dotenv = require("dotenv");
const path = require("path");
dotenv.config();
async function clearRemoteDirectory() {
const client = new FtpClient.Client();
try {
const host = process.env.FTP_HOST;
const username = process.env.FTP_USER;
const password = process.env.FTP_PASS;
await client.access({
host,
user: username,
password,
secure: false,
});
const remotePath = process.env.FTP_REMOTE_PATH;
const buildPath = path.join(__dirname, 'build');
await client.cd(remotePath);
const currentRemoteDir = await client.pwd();
console.log(`Huidige remote directory is: ${currentRemoteDir}`);
await client.clearWorkingDir();
console.log(`Inhoud van de remote directory ${remotePath} is verwijderd.`);
await client.uploadFromDir(buildPath, process.env.FTP_REMOTE_PATH);
console.log(`Upload klaar, geef mij een appel.\n🍎`);
} catch (error) {
console.error("Er is een fout opgetreden:", error);
} finally {
client.close();
}
}
clearRemoteDirectory();