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

)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值