-
Notifications
You must be signed in to change notification settings - Fork 1
/
ftp.js
60 lines (56 loc) · 1.66 KB
/
ftp.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
59
60
var FtpDeploy = require("ftp-deploy");
var ftpDeploy = new FtpDeploy();
const dotenv = require("dotenv");
dotenv.config();
var config = {
user: process.env.FTP_USER,
// Password optional, prompted if none given
password: process.env.FTP_PASSWORD,
host: process.env.FTP_HOST,
port: 21,
localRoot: __dirname + "/build",
remoteRoot: process.env.FTP_REMOTE_ROOT,
// include: ["*", "**/*"], // this would upload everything except dot files
include: ["*", ".*"],
// e.g. exclude sourcemaps, and ALL files in node_modules (including dot files)
exclude: [
"dist/**/*.map",
"node_modules/**",
"node_modules/**/.*",
".git/**",
"**/.DS_Store",
],
// delete ALL existing files at destination before uploading, if true
deleteRemote: false,
// Passive mode is forced (EPSV command is not sent)
forcePasv: true,
};
// use with promises
ftpDeploy
.deploy(config)
// .then(res => console.log("finished:", res))
.catch((err) => console.log(err));
// use with callback
// ftpDeploy.deploy(config, function (err, res) {
// if (err) console.log(err);
// else console.log("finished:", res);
// });
ftpDeploy.on("uploading", function (data) {
console.log(
data.transferredFileCount +
" of " +
data.totalFilesCount +
": '" +
data.filename +
"'"
);
});
// ftpDeploy.on("uploaded", function (data) {
// console.log(data); // same data as uploading event
// });
// ftpDeploy.on("log", function (data) {
// console.log(data); // same data as uploading event
// });
ftpDeploy.on("upload-error", function (data) {
console.log(data.err); // data will also include filename, relativePath, and other goodies
});