安装
API
rmdir(romotePath, true)
递归删除服务器文件夹uploadDir(localPath, romotePath)
递归上传文件夹put(localPath, romotePath)
get(romotePath, localPath)
demo
const Client = require('ssh2-sftp-client')
const config = {
path: {
romotePath,
localPath,
},
romote: {
host,
port,
username,
password,
}
}
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('----------------------------- 出错了!! -----------------------------')
console.log(err)
})
.finally(() => {
sftp.end()
})
}
main(
config.path.localPath,
config.path.romotePath,
)