ftp-relay-cli
v0.1.3
Published
CLI for uploading static assets to FTP Relay (auto CI/git headers)
Readme
ftp-relay-cli
上传静态产物到 FTP Relay 的命令行工具。
自动从 GitLab / GitHub CI 环境变量(或本地 git)填充审计 Header,无需手写一长串 curl -H。
安装
npm install -g ftp-relay-cli
# 或项目内
npm install -D ftp-relay-clinpx ftp-relay upload ./dist --url http://127.0.0.1:8080 --token tok_xxx --wait用法
export FTP_RELAY_URL=http://127.0.0.1:8080
export FTP_RELAY_TOKEN=tok_xxxxxxxx
# 上传目录(默认打成 tgz 压缩包;自动带 X-Remote-Subdir=<目录名>,落到项目 remotePath 下)
ftp-relay upload ./202607101806 --wait
# 例:项目 remotePath=/test-ftp → 远端 /test-ftp/202607101806
# 不压缩(仅 tar)
ftp-relay upload ./dist --format tar --wait
# 已有归档(不带 X-Remote-Subdir,内容直接落到 remotePath)
ftp-relay upload ./dist.tar --waitGitLab CI 示例
deploy:
script:
- npx -y -p ftp-relay-cli ftp-relay upload ./dist --wait
variables:
FTP_RELAY_URL: "https://ftp-relay.example.com"
# FTP_RELAY_TOKEN 配在 CI 变量里CI 下会自动带上:
| Header | 来源 |
|--------|------|
| X-Source | ci |
| X-Commit | CI_COMMIT_SHA / GITHUB_SHA / git rev-parse HEAD |
| X-Branch | CI_COMMIT_REF_NAME / GITHUB_REF_NAME |
| X-Actor | GITLAB_USER_LOGIN / GITHUB_ACTOR / git user.name |
| X-Repo | CI_PROJECT_PATH / GITHUB_REPOSITORY |
| X-Pipeline-Url | CI_PIPELINE_URL / GitHub Actions run URL |
可用 --commit / --actor 等覆盖。
选项
ftp-relay upload <dir|archive>
--url <url> 或环境变量 FTP_RELAY_URL
--token <token> 或环境变量 FTP_RELAY_TOKEN
--format tar|tgz 目录打包格式,默认 tgz
--wait 同步等待结果
--source / --commit / --branch / --actor / --repo / --pipeline-url作为库
import { upload } from "ftp-relay-cli";
await upload({
url: process.env.FTP_RELAY_URL!,
token: process.env.FTP_RELAY_TOKEN!,
path: "./dist",
wait: true,
});