File size: 1,756 Bytes
eccbbd1
a4be0a3
eccbbd1
 
 
 
 
 
 
 
 
 
 
 
 
a4be0a3
 
 
eccbbd1
 
 
dd66be3
a4be0a3
eccbbd1
a4be0a3
eccbbd1
 
 
 
 
a4be0a3
eccbbd1
 
 
 
 
 
 
 
 
 
 
 
 
 
a4be0a3
eccbbd1
a4be0a3
 
 
eccbbd1
a4be0a3
 
 
eccbbd1
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
// upload.js
const ftp = require("basic-ftp");
const path = require("path");

async function upload() {
  const host = process.env["FTP_HOST"] || "ftpupload.net";
  const user = process.env["FTPname"];
  const password = process.env["FTPpsw"];
  const port = process.env["FTP_PORT"] || 21;

  if (!user || !password) {
    console.log("FTP環境変数が設定されていないため、アップロードをスキップします。");
    console.log("必要な環境変数: FTPname(ユーザー名), FTPpsw(パスワード)");
    return;
  }

  const client = new ftp.Client();
  client.ftp.verbose = true;
  client.ftp.timeout = 300000;

  console.log("FTPアップロードを開始します...");

  try {
    console.log(`接続中: ${host}:${port} (ユーザー: ${user})`);
    await client.access({
      host,
      user,
      password,
      port,
      secure: false,
    });
    console.log("FTPサーバーへの接続に成功しました。");

    const remoteDir = "s4s-editor.ct.ws/htdocs/";
    console.log(`リモートディレクトリに移動または作成: ${remoteDir}`);
    await client.ensureDir(remoteDir);

    console.log("既存のリモートディレクトリの内容をクリア中...");
    await client.clearWorkingDir();

    const localDist = path.join(__dirname, "dist");
    console.log(`ローカルディレクトリをアップロード中: ${localDist}`);
    await client.uploadFromDir(localDist);

    console.log("✅ アップロードが完了しました。");
  } catch (err) {
    console.error("❌ アップロード中にエラーが発生しました:");
    console.error(err);
  } finally {
    client.close();
    console.log("FTP接続を閉じました。");
  }
}

upload();