-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchainProcessJSON.js
58 lines (47 loc) · 1.25 KB
/
chainProcessJSON.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require("dotenv").config();
const Client = require("ftp");
const fs = require("fs");
const jsonEventsFolderLocal = `./json/`;
const jsonEventsFolderLocalSent = `./json/sent/`;
const jsonEventsFolderServer = process.env["FTP_JSON_FOLDER"];
let localFile;
let serverFile;
let jsonCount = 0;
// Get JSON files
class MoveJSON {
UploadJSONFiles() {
console.log("Upload JSON Files");
const c = new Client();
fs.readdirSync(jsonEventsFolderLocal).forEach((file) => {
fs.stat(`${jsonEventsFolderLocal}${file}`, function (err, stats) {
if (err) console.log(err);
if (stats.isFile()) {
jsonCount++;
localFile = `${jsonEventsFolderLocal}${file}`;
serverFile = `${jsonEventsFolderServer}${file}`;
c.put(localFile, serverFile, function (err) {
if (err) throw err;
console.log(`>> FTPing ${file}`);
c.end();
});
}
});
});
c.connect({
host: process.env["FTP_HOST"],
user: process.env["FTP_USER"],
password: process.env["FTP_PASSWORD"],
});
return this;
}
ProcessJSONFiles() {
console.log("Process JSON Files");
return this;
}
EmailStatus() {
console.log("Emailing");
return this;
}
}
const moveJSONfiles = new MoveJSON();
moveJSONfiles.UploadJSONFiles().ProcessJSONFiles().EmailStatus();