{"id":21148778,"url":"https://github.com/2ue/ssh2-to-remote-action","last_synced_at":"2025-09-15T08:18:05.048Z","repository":{"id":236705662,"uuid":"793001651","full_name":"2ue/ssh2-to-remote-action","owner":"2ue","description":"An action to upload to a remote server via ssh2","archived":false,"fork":false,"pushed_at":"2025-08-09T15:09:07.000Z","size":1214,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-09T17:24:24.677Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/2ue.png","metadata":{"files":{"readme":"README-cn.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-04-28T06:31:27.000Z","updated_at":"2025-08-09T15:09:04.000Z","dependencies_parsed_at":"2024-04-28T08:23:39.069Z","dependency_job_id":"bd7362ef-3020-4baf-9593-4a720f1a8e33","html_url":"https://github.com/2ue/ssh2-to-remote-action","commit_stats":null,"previous_names":["2ue/ssh2-to-remote-action"],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/2ue/ssh2-to-remote-action","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2ue%2Fssh2-to-remote-action","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2ue%2Fssh2-to-remote-action/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2ue%2Fssh2-to-remote-action/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2ue%2Fssh2-to-remote-action/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2ue","download_url":"https://codeload.github.com/2ue/ssh2-to-remote-action/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2ue%2Fssh2-to-remote-action/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275225974,"owners_count":25427022,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-15T02:00:09.272Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-20T09:28:58.119Z","updated_at":"2025-09-15T08:18:05.038Z","avatar_url":"https://github.com/2ue.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SSH2 SFTP 上传 Action\n\n[![CI](https://github.com/2ue/ssh2-to-remote-action/actions/workflows/ci.yml/badge.svg)](https://github.com/2ue/ssh2-to-remote-action/actions/workflows/ci.yml)\n[![Coverage Status](./badges/coverage.svg)](./badges/coverage.svg)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n一个强大的 GitHub Action，用于通过 SSH2 SFTP 协议将本地目录上传到远程服务器。使用 TypeScript 构建，具有全面的错误处理机制。\n\n[English](./README.md) | [中文文档](./README-cn.md)\n\n## ✨ 特性\n\n- 🚀 **TypeScript** - 类型安全，全面的错误处理\n- 🔐 **多种认证方式** - 支持密码、私钥或 SSH 代理认证\n- 📁 **目录上传** - 上传整个目录并追踪进度\n- 💾 **备份支持** - 上传前可选的远程目录备份\n- 🔄 **重试机制** - 可配置的连接重试和指数退避\n- 📊 **详细输出** - 追踪上传文件数量和操作状态\n- ⚡ **并发操作** - 可配置的并发限制以优化性能\n- 🛡️ **安全优先** - 不记录敏感信息，安全的连接处理\n\n## 📦 使用方法\n\n### 基本用法\n\n```yaml\nname: 部署到服务器\non:\n  push:\n    branches: [ main ]\n\njobs:\n  deploy:\n    runs-on: ubuntu-latest\n    steps:\n      - name: 检出代码\n        uses: actions/checkout@v4\n        \n      - name: 上传到服务器\n        uses: 2ue/ssh2-to-remote-action@v1\n        with:\n          host: ${{ secrets.SERVER_HOST }}\n          username: ${{ secrets.SERVER_USERNAME }}\n          password: ${{ secrets.SERVER_PASSWORD }}\n          local_dir: './dist'\n          remote_base_dir: '/var/www/html'\n```\n\n### 高级用法（私钥认证 + 备份）\n\n```yaml\n      - name: 上传并备份\n        uses: 2ue/ssh2-to-remote-action@v1\n        with:\n          host: ${{ secrets.SERVER_HOST }}\n          port: 2222\n          username: ${{ secrets.SERVER_USERNAME }}\n          privateKey: ${{ secrets.SSH_PRIVATE_KEY }}\n          passphrase: ${{ secrets.SSH_PASSPHRASE }}\n          local_dir: './build'\n          remote_base_dir: '/home/user/app'\n          remote_bak_path: '/home/user/backups'\n          retries: 3\n          retry_factor: 2\n          readyTimeout: 30000\n          debug: true\n```\n\n## 📋 输入参数\n\n### 必需参数\n\n| 参数 | 描述 | 示例 |\n|------|------|------|\n| `host` | 远程服务器主机名或 IP | `example.com` |\n| `username` | SSH 用户名 | `ubuntu` |\n| `local_dir` | 要上传的本地目录 | `./dist` |\n| `remote_base_dir` | 远程目标目录 | `/var/www/html` |\n\n### 认证方式（选择其一）\n\n| 参数 | 描述 | 示例 |\n|------|------|------|\n| `password` | SSH 密码 | `${{ secrets.PASSWORD }}` |\n| `privateKey` | SSH 私钥内容 | `${{ secrets.SSH_KEY }}` |\n| `agent` | SSH 代理套接字路径 | `/tmp/ssh-agent.sock` |\n\n### 可选参数\n\n| 参数 | 描述 | 默认值 | 示例 |\n|------|------|--------|------|\n| `port` | SSH 端口 | `22` | `2222` |\n| `passphrase` | 私钥密码短语 | | `${{ secrets.PASSPHRASE }}` |\n| `remote_bak_path` | 备份目录路径 | | `/backups` |\n| `forceIPv4` | 强制 IPv4 连接 | `false` | `true` |\n| `forceIPv6` | 强制 IPv6 连接 | `false` | `true` |\n| `readyTimeout` | SSH 握手超时时间（毫秒） | `20000` | `30000` |\n| `strictVendor` | 严格服务器供应商检查 | `false` | `true` |\n| `debug` | 启用调试日志 | `false` | `true` |\n| `retries` | 连接重试次数 | `1` | `3` |\n| `retry_factor` | 重试延时倍数 | `2` | `1.5` |\n| `retry_minTimeout` | 最小重试延时（毫秒） | `1000` | `2000` |\n| `promiseLimit` | 并发操作限制 | `10` | `5` |\n\n## 📤 输出\n\n| 输出 | 描述 | 示例 |\n|------|------|------|\n| `uploaded_files` | 上传的文件数量 | `42` |\n| `success` | 上传操作状态 | `true` |\n| `error` | 失败时的错误信息 | `连接超时` |\n\n## 🔒 安全注意事项\n\n### 密钥管理\n\n将敏感信息存储为 GitHub 仓库密钥：\n\n1. 进入你的仓库 → Settings → Secrets and variables → Actions\n2. 添加以下密钥：\n   - `SERVER_HOST` - 服务器主机名\n   - `SERVER_USERNAME` - SSH 用户名\n   - `SERVER_PASSWORD` - SSH 密码（使用密码认证时）\n   - `SSH_PRIVATE_KEY` - SSH 私钥内容（使用密钥认证时）\n   - `SSH_PASSPHRASE` - 私钥密码短语（如需要）\n\n### SSH 密钥认证（推荐）\n\n为了更好的安全性，建议使用 SSH 密钥认证：\n\n```bash\n# 生成 SSH 密钥对\nssh-keygen -t rsa -b 4096 -C \"github-actions@your-repo\"\n\n# 将公钥复制到服务器\nssh-copy-id -i ~/.ssh/id_rsa.pub user@server\n\n# 将私钥内容添加到 GitHub 密钥中，命名为 SSH_PRIVATE_KEY\ncat ~/.ssh/id_rsa\n```\n\n## 🚀 使用示例\n\n### 部署 React 应用\n\n```yaml\nname: 部署 React 应用\non:\n  push:\n    branches: [ main ]\n\njobs:\n  deploy:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v4\n      \n      - name: 设置 Node.js\n        uses: actions/setup-node@v4\n        with:\n          node-version: '20'\n          \n      - name: 安装依赖并构建\n        run: |\n          npm ci\n          npm run build\n          \n      - name: 部署到服务器\n        uses: 2ue/ssh2-to-remote-action@v1\n        with:\n          host: ${{ secrets.SERVER_HOST }}\n          username: ${{ secrets.SERVER_USERNAME }}\n          privateKey: ${{ secrets.SSH_PRIVATE_KEY }}\n          local_dir: './build'\n          remote_base_dir: '/var/www/html'\n          remote_bak_path: '/var/backups/www'\n          \n      - name: 检查部署状态\n        if: success()\n        run: echo \"✅ 成功部署了 ${{ steps.deploy.outputs.uploaded_files }} 个文件！\"\n```\n\n### 多环境部署\n\n```yaml\nname: 多环境部署\non:\n  push:\n    branches: [ main, staging ]\n\njobs:\n  deploy:\n    runs-on: ubuntu-latest\n    strategy:\n      matrix:\n        environment: \n          - name: staging\n            branch: staging\n            host: staging.example.com\n            path: /var/www/staging\n          - name: production\n            branch: main\n            host: example.com\n            path: /var/www/html\n            \n    steps:\n      - uses: actions/checkout@v4\n        if: github.ref == format('refs/heads/{0}', matrix.environment.branch)\n        \n      - name: 部署到 ${{ matrix.environment.name }}\n        if: github.ref == format('refs/heads/{0}', matrix.environment.branch)\n        uses: 2ue/ssh2-to-remote-action@v1\n        with:\n          host: ${{ matrix.environment.host }}\n          username: ${{ secrets.SERVER_USERNAME }}\n          privateKey: ${{ secrets.SSH_PRIVATE_KEY }}\n          local_dir: './dist'\n          remote_base_dir: ${{ matrix.environment.path }}\n          remote_bak_path: '/backups/${{ matrix.environment.name }}'\n          retries: 3\n          debug: true\n```\n\n### Docker 应用部署\n\n```yaml\nname: Docker 应用部署\non:\n  push:\n    branches: [ main ]\n\njobs:\n  deploy:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v4\n      \n      - name: 构建 Docker 镜像\n        run: |\n          docker build -t myapp:latest .\n          docker save myapp:latest \u003e myapp.tar\n          \n      - name: 上传 Docker 镜像\n        uses: 2ue/ssh2-to-remote-action@v1\n        with:\n          host: ${{ secrets.SERVER_HOST }}\n          username: ${{ secrets.SERVER_USERNAME }}\n          privateKey: ${{ secrets.SSH_PRIVATE_KEY }}\n          local_dir: './myapp.tar'\n          remote_base_dir: '/opt/deploy'\n          \n      - name: 部署 Docker 容器\n        uses: appleboy/ssh-action@v1.0.0\n        with:\n          host: ${{ secrets.SERVER_HOST }}\n          username: ${{ secrets.SERVER_USERNAME }}\n          key: ${{ secrets.SSH_PRIVATE_KEY }}\n          script: |\n            cd /opt/deploy\n            docker load \u003c myapp.tar\n            docker stop myapp || true\n            docker rm myapp || true\n            docker run -d --name myapp -p 80:3000 myapp:latest\n```\n\n## 🛠️ 开发\n\n### 前置要求\n\n- Node.js 20+\n- TypeScript\n- Jest 测试框架\n\n### 设置\n\n```bash\n# 克隆仓库\ngit clone https://github.com/2ue/ssh2-to-remote-action.git\ncd ssh2-to-remote-action\n\n# 安装依赖\nnpm install\n\n# 构建 TypeScript\nnpm run build\n\n# 运行测试\nnpm test\n\n# 运行所有检查\nnpm run all\n```\n\n### 项目结构\n\n```\nsrc/\n├── config/          # 输入验证和处理\n├── ssh/             # SSH 连接管理\n├── upload/          # 文件上传逻辑\n├── types/           # TypeScript 类型定义\n├── main.ts          # 主要 Action 逻辑\n└── index.ts         # 入口点\n\n__tests__/           # 测试文件\ndist/                # 编译输出\n```\n\n## 🤝 贡献\n\n1. Fork 这个仓库\n2. 创建特性分支：`git checkout -b feature/amazing-feature`\n3. 进行更改并添加测试\n4. 运行测试套件：`npm run all`\n5. 提交更改：`git commit -m 'Add amazing feature'`\n6. 推送到分支：`git push origin feature/amazing-feature`\n7. 开启 Pull Request\n\n## 🐛 故障排除\n\n### 常见问题\n\n**连接超时**\n```yaml\n# 增加超时时间\nreadyTimeout: 30000  # 30秒\nretries: 3\n```\n\n**权限被拒绝**\n```bash\n# 检查服务器权限\nssh user@server 'ls -la /target/directory'\n```\n\n**私钥格式问题**\n```bash\n# 确保私钥格式正确\nssh-keygen -p -m PEM -f ~/.ssh/id_rsa\n```\n\n**上传速度慢**\n```yaml\n# 调整并发限制\npromiseLimit: 5  # 减少并发数\n```\n\n## 📄 许可证\n\n本项目使用 MIT 许可证 - 查看 [LICENSE](LICENSE) 文件了解详情。\n\n## 🙏 致谢\n\n- 基于 [ssh2-sftp-client](https://github.com/theophilusx/ssh2-sftp-client) 构建\n- 由 [GitHub Actions](https://github.com/features/actions) 驱动\n- TypeScript 支持通过 [@actions/core](https://github.com/actions/toolkit/tree/main/packages/core) 提供\n\n## 📞 支持\n\n- 🐛 [报告问题](https://github.com/2ue/ssh2-to-remote-action/issues)\n- 💡 [功能请求](https://github.com/2ue/ssh2-to-remote-action/issues/new?template=feature_request.md)\n- 📖 [文档](https://github.com/2ue/ssh2-to-remote-action/wiki)\n\n## 🆚 与其他工具对比\n\n| 功能 | ssh2-to-remote-action | scp-action | rsync-action |\n|------|----------------------|------------|--------------|\n| TypeScript | ✅ | ❌ | ❌ |\n| 备份功能 | ✅ | ❌ | ❌ |\n| 重试机制 | ✅ | ❌ | ✅ |\n| 进度追踪 | ✅ | ❌ | ❌ |\n| 多种认证 | ✅ | ✅ | ✅ |\n| 错误处理 | ✅ | 基础 | 基础 |\n\n---\n\n用 ❤️ 为 GitHub Actions 社区打造","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2ue%2Fssh2-to-remote-action","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2ue%2Fssh2-to-remote-action","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2ue%2Fssh2-to-remote-action/lists"}