-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib.js
36 lines (32 loc) · 844 Bytes
/
lib.js
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
const Client = require('scp2')
const colors = require('colors')
const path = require('path')
class NodeSftp {
/**
* host: '',
* username: 'root',
* password: '',
* local: '', 上传的本地文件、文件夹
* path: '',
* handleMode: false
*/
constructor(options = {}) {
this.options = Object.assign({ port: 22, username: 'root', local: 'dist' }, options)
this.startTime = null
}
init() {
this.startTime = Date.now()
console.log(colors.rainbow('\nStart upload, please wait...'))
this.upload(path.join(this.options.local), this.options)
}
/**
* opts
*/
upload(local, opts) {
Client.scp(local, opts, err => {
if (err) throw err
console.log(colors.green(`Uploaded ${local} successfully in ${Date.now() - this.startTime}ms`))
})
}
}
module.exports = NodeSftp