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

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

  if (!user || !password) {
    console.error("環境変数 'FTPname' または 'FTPpsw' が設定されていません。");
    return;
  }

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

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

  try {
    console.log(`接続中: ${host}`);
    await client.access({
      host,
      user,
      password,
      secure: false,
    });
    console.log("接続に成功しました。");

    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(`ローカルの 'dist' ディレクトリをアップロード中: ${localDist}`);
    await client.uploadFromDir(localDist);

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

upload();