Spaces:
Build error
Build error
Create ftp-upload.js
Browse files- ftp-upload.js +40 -0
ftp-upload.js
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// upload.js
|
2 |
+
const ftp = require("basic-ftp");
|
3 |
+
const path = require("path");
|
4 |
+
|
5 |
+
async function upload() {
|
6 |
+
// 環境変数からFTP情報を取得
|
7 |
+
const host = "ftpupload.net";
|
8 |
+
const user = process.env["FTP-name"];
|
9 |
+
const password = process.env["FTP-psw"];
|
10 |
+
|
11 |
+
if (!user || !password) {
|
12 |
+
// 環境変数がなければ何もせず終了
|
13 |
+
return;
|
14 |
+
}
|
15 |
+
|
16 |
+
const client = new ftp.Client();
|
17 |
+
client.ftp.verbose = true;
|
18 |
+
|
19 |
+
try {
|
20 |
+
await client.access({
|
21 |
+
host,
|
22 |
+
user,
|
23 |
+
password,
|
24 |
+
secure: false,
|
25 |
+
});
|
26 |
+
|
27 |
+
// アップロード先ディレクトリ
|
28 |
+
await client.ensureDir("s4s-editor.ct.ws/htdocs/");
|
29 |
+
await client.clearWorkingDir();
|
30 |
+
|
31 |
+
// ローカルのdistフォルダをアップロード
|
32 |
+
await client.uploadFromDir(path.join(__dirname, "dist"));
|
33 |
+
} catch (err) {
|
34 |
+
console.error(err);
|
35 |
+
} finally {
|
36 |
+
client.close();
|
37 |
+
}
|
38 |
+
}
|
39 |
+
|
40 |
+
upload();
|