200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > linux上传文件至指定目录下 node上传文件到linux服务器指定路径

linux上传文件至指定目录下 node上传文件到linux服务器指定路径

时间:2019-01-12 22:41:35

相关推荐

linux上传文件至指定目录下 node上传文件到linux服务器指定路径

'use strict'

const Client = require('ssh2-sftp-client')

const config = {

path: {

// 远程地址

romotePath:'/data/app/test/vue/dist/',

// 本地地址

localPath: './dist'

},

romote: {

// 服务器 ip 地址

host: 'x.x.x.x',

// 端口号,默认是 22

port: '22',

// 登录的用户名

username: 'root',

// 登录密码

password: 'xxxxxx'

}

}

/* 主方法

* @method main

* @param{String} localPath 本地路径,不用 path 模块,直接字符串就好了,这个包自己有格式化的

* @param{String} romotePath 远程路径

* @return{undefined} 返回个*

*/

function main(localPath, romotePath) {

// 实例化

const sftp = new Client()

sftp

.connect(config.romote)

.then(() => {

console.log('----------------------------- 连接成功,上传中... -----------------------------')

return sftp.uploadDir(localPath, romotePath)

})

.then(data => {

console.log('----------------------------- 上传完成,及时清除缓存 ----------------------------')

})

.catch(err => {

console.log('----------------------------- TMD失败了!出事了!快看看怎么回事! -----------------------------')

console.log(err)

})

.finally(() => {

// 断开连接

sftp.end()

})

}

main(

config.path.localPath,

config.path.romotePath

)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。