@leizm/sftt
简单文件传输工具
Last updated 2 years ago by leizongmin .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @leizm/sftt 
SYNC missed versions from official npm registry.

@leizm/sftt

简单文件传输工具

安装

npm i -g @leizm/sftt

命令行工具使用

启动服务器端

使用方法:

sftt-server --help

  Usage: sftt-server [options]

  Options:

    -V, --version      output the version number
    -i, --ip <ip>      允许的来源IP地址,多个地址通过逗号分隔 (default: 127.0.0.1)
    -p, --port <port>  监听的端口 (default: 12345)
    -h, --host <host>  监听的地址 (default: 0.0.0.0)
    -d, --dir <dir>    文件根目录 (default: .)
    -c, --config <config_file>  指定配置文件
    -h, --help         output usage information

示例:

sftt-server --ip 192.168.1.2,127.0.0.1 --port 12345 --host 0.0.0.0 --dir /data

客户端上传文件

使用方法:

sftt-put --help

  Usage: sftt-put [options]

  Options:

    -V, --version          output the version number
    -f, --file <file>      要上传的文件 (default: )
    -d, --dir <dir>        要上传的目录 (default: )
    -s, --server <server>  远程服务器地址(host:port/path) (default: 127.0.0.1:12345/data)
    -c, --config <config_file>  指定配置文件
    -h, --help             output usage information

示例:

# 上传文件
sftt-put --server 127.0.0.1:12345/dir1 --file test.txt
# 上传整个目录下的所有文件
sftt-put --server 127.0.0.1:12345/dir2 --dir data
# 使用token权限验证
sftt-put --server token@127.0.0.1:12345/dir1 --file test.txt

通过 PM2 启动服务器端

新建 sftt-server 配置文件 server.config.json

{
  "ip": "127.0.0.1",
  "port": 12345,
  "host": "0.0.0.0",
  "dir": "./data"
}

新建 PM2 配置文件 sftt-server.pm2.yaml

apps:
  - name: sftt-server
    script: /usr/local/bin/sftt-server
    instances: 1
    exec_mode: fork
    args:
      - "--config"
      - "server.config.json"

说明:

  • script 中的 /usr/local/bin/sftt-serversftt-server 命令的绝对文件路径,可以通过执行 which sftt-server 获得
  • args 部分为相应的命令行参数

然后,执行以下命令即可通过 PM2 启动:

pm2 start sftt-server.pm2.yaml

作为模块嵌入

上传文件

import { putFile, putDir } from "@leizm/sftt";

async function main() {

  // 上传指定文件到服务器
  const {key, md5} = await putFile({
    host: '127.0.0.1',
    port: 12345,
    path: '/',
  }, '/path/to/local/file');

  // 上传指定目录下的多有文件到服务器
  const ret = await putDir({
    host: '127.0.0.1',
    port: 12345,
    path: '/',
  }, '/path/to/local/dir', (type, data) => {
    console.log('进度', type, data);
  });

}

License

MIT License

Copyright (c) 2018 Zongmin Lei <leizongmin@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Current Tags

  • 1.5.0                                ...           latest (2 years ago)

13 Versions

  • 1.5.0                                ...           2 years ago
  • 1.4.0                                ...           2 years ago
  • 1.3.3                                ...           2 years ago
  • 1.3.2                                ...           2 years ago
  • 1.3.1                                ...           2 years ago
  • 1.3.0                                ...           2 years ago
  • 1.2.1                                ...           2 years ago
  • 1.2.0                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 5
Last Day 0
Last Week 1
Last Month 7
Dependencies (9)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |