# easeftp

> cdn 上传工具

Latest version **2.0.40** (published 2018-07-11) · ISC license · 0 weekly downloads

## Install

```sh
npm install easeftp
pnpm add easeftp
yarn add easeftp
bun add easeftp
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.40 |
| Published | 2018-07-11 |
| First published | 2017-10-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 2.1 MB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| Author | sweetehs,wwl |
| Maintainers | wwl |

## Links

- npm: https://www.npmjs.com/package/easeftp
- npm.io page: https://npm.io/package/easeftp

## Dependencies (10)

- [glob](https://npm.io/package/glob.md) ^7.1.2
- [colors](https://npm.io/package/colors.md) ^1.1.2
- [crypto](https://npm.io/package/crypto.md) ^1.0.1
- [needle](https://npm.io/package/needle.md) ^2.2.0
- [request](https://npm.io/package/request.md) ^2.82.0
- [bluebird](https://npm.io/package/bluebird.md) ^3.5.1
- [wwl-hash](https://npm.io/package/wwl-hash.md) ^1.0.1
- [minimatch](https://npm.io/package/minimatch.md) ^3.0.4
- [mime-types](https://npm.io/package/mime-types.md) ^2.1.18
- [string-to-stream](https://npm.io/package/string-to-stream.md) ^1.1.1

## Recent versions

- 2.0.40 (latest) — 2018-07-11
- 2.0.39 — 2018-05-30
- 2.0.38 — 2018-05-30
- 2.0.37 — 2018-05-30
- 2.0.36 — 2018-05-30
- 2.0.35 — 2018-05-29
- 2.0.34 — 2018-05-29
- 2.0.32 — 2018-05-16
- 2.0.31 — 2018-05-16
- 2.0.30 — 2018-05-10
- 2.0.29 — 2018-05-10
- 2.0.28 — 2018-05-10
- 2.0.27 — 2018-05-07
- 2.0.26 — 2018-05-07
- 2.0.25 — 2018-04-27
- … 48 more at https://npm.io/package/easeftp/versions

## README

cdn 上传工具

# 依赖

node : 8.x

# 示例1 上传文件
```javascript
const addFile = require('easeftp/upload').addFile;

addFile(['**/**'],{
    username:'wwl',     //用户名,     必填
    password:'123',     //密码,       必填
    path:'f2e/test',    //cdn线上路径, 必填
    cwd:'./dist',       //匹配的根目录,     默认为process.cwd()
    exclude:['*.map'],  //排除不上传的文件,  默认为空   
    debug:true,         //是否开启日志打印,  默认为false
    // otppwd:'123456'  //将军令，外网环境需要传入将军令
}).then((data) =>{
    console.log(data.urls);      //上传成功的访问url    eg: https://static.ws.126.net/163/f2e/test/app.js
},(data) => {
     console.log(data.details);  //所有详细信息
})
```

# 示例2 上传文本
```javascript
    const addContent = require('easeftp/upload').addContent;
    addContent('var a=1;', 'testAddContent.js', {
        username:'...', password:'...',
        path: 'f2e/test',
        debug: true,    //默认为false
        // otppwd:'123456'  //将军令，外网环境需要传入将军令
    }).then(
        (data) => console.log(data.url),    // https://static.ws.126.net/163/f2e/test/testAddContent.js
        (data) => console.log(data.detail)
    )
```


# 注意
> * 服务器为UTF8编码。
> * 账号密码要单独建立config文件，以免错误的提交到git上。
> * 注意区分  `require('easeftp/upload)` 和 [version1:`require('easeftp')`](#version-1)。建议使用 `easeftp/upload`。

# addFile()

`function addFile(files , {username, password, otppwd,  path, cwd, exclude, debug, strict, fileName } )`

### files

string | array , 必填

支持glob语法，例如: "\*\*/\*.js"

内部通过glob组件匹配文件。语法详情参考:[glob](https://www.npmjs.com/package/glob)

### username , password 

string,必填

无权限的用户，需要先申请权限

### otppwd

string,将军令，外网环境必填，公司内网不需要。

### path

string | function(filePath) ,默认为`"f2e/test"`

设置上传cdn后的url路径。

上传成功后的url地址为: `https://static.ws.126.net/163/${path}/${fileName}` 例如 `path:'f2e/test'`， 则上传成功后，访问路径为:`https://static.ws.126.net/163/f2e/test/xxx`。

也可以设置为function类型，接收string类型的filePath参数，为即将上传的文件绝对路径，转化为url路径。
例如;
```javascript
addFile('**/*.js', {
    username:'xxx',password:'xxx',
    cwd:'./dist',
    path(filePath){
        if(filePath.indexOf('test.js')){
            return 'f2e/test'
        }
        else{
            return 'f2e/dist'
        }
    }
}).then(({urls, details}) => {
    console.log(urls);
   /*[ 'https://static.ws.126.net/163/f2e/dist/app.js',
       'https://static.ws.126.net/163/f2e/test/test.js' ]*/
})


```

### cwd

string,可选,默认为 process.cwd().

指定查找的目录。

当pattern为相对路径时，在会在cwd下查找匹配的文件。例如:
```javascript
//只上传dist目录下的js文件。
addFile('*.js',{
    username:username, password:password, path:'f2e/test', 
    cwd:'./dist'
});
```

cwd可以是绝对路径,也可以是相对路径。如果cwd为相对路径，是相对于process.cwd()的。


### exclude

Array,可选,默认为空数组。

设置不匹配的文件。
例如如下示例：会查找`./dist`下的不是`.html`后缀和`.map`后缀的文件。
```javascript
addFile(['**/*.*'],{ 
    username:'...',password:'...',path:'f2e/test',
    cwd:'./dist',
    exclude:['*.html','*.map']
})
```


### debug 

bool,可选,默认为 false

是否在控制台开启调试打印信息


### strict

bool,可选,默认为true.

是否严格限定上传的目录结构。
为true时，上传到cdn的目录结构和本地目录结构一致，例如:

```javascript

/*
假设dist目录结构为:
./dist
├── app.js
└── lib
    └── ajax.js
    
*/
addFile('**/*.js', {
    username:'xxx',password:'xxx',
    path: 'f2e/test/',
    cwd:'./dist',
    strict:true
}).then(({urls, details}) => {
    console.log(urls);
   /*[ 'https://static.ws.126.net/163/f2e/test/app.js',
       'https://static.ws.126.net/163/f2e/test/lib/ajax.js' ]*/
})

addFile('**/*.js', {
    username:'xxx',password:'xxx',
    path: 'f2e/test/',
    cwd:'./dist',
    strict:false,
}).then(({urls, details}) => {
    console.log(urls);
   /*   [ 'https://static.ws.126.net/163/f2e/test/app.js',
          'https://static.ws.126.net/163/f2e/test/ajax.js' ]*/
})

```

### fileName

`function(filePath)`,可选,

默认上传文件名和本地文件名一致。

可以通过该回调更改文件名。
```javascript
 var addFile=require('easeftp/upload').addFile;
 var path=require('path');
 addFile(['**/**'], {
        username: 'wwl',password: '123',
        path: 'f2e/test',
        cwd: './dist',
        fileName(filePath) {
            return path.basename(filePath).replace('.min', '');
        }
    })
```


# addContent()

`function addFile(content, filename, {username, password, otppwd, debug , path })`


### content

String|Buffer, 文本内容。

### filename

String, 文件名称，需要带有后缀名。 例如: "test.js"

### username, password, path , debug 

和 addFile() 参数作用相同

其中，path值支持string类型(addFile()中的path参数支持function类型。)

----------


# Version 1


## 示例
```javascript
var easeftp = require('easeftp');
easeftp.verify({
	"username": "...",
	"password": "...",
	//otppwd:'...'
}).then(function() {
	return easeftp.upload({
		online: "test/test1/......",
		file: "绝对路径", 	// 需要上传的文件路径
		files: "绝对路径", 	// 需要上传的文件夹路径
						  	// 文件和文件夹只能选择其一，否则按照文件上传处理
		exclude:["*.js","**.js","..."]   // 排除其中不上传的文件
	})
}).then(([successArr,failArr]) => {
	// successArr 	上传成功
	// failArr 		上传失败
	// complete
})
```

## 说明

v1内部还是require的`easeftp/upload`，只不过兼容之前的参数形式。

如果要使用原v1的代码，使用如下形式:

```javascript
var easeftp = require('easeftp/index_v1');
```

---
_Source: https://npm.io/package/easeftp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
