12345678910111213141516171819202122232425262728293031323334353637383940 |
- const shell = require('shelljs')
- const path = require('path');
- const config = {
- ip: "47.115.219.94",
- username: "root",
- port: 22,
- password: "DStech@123",
- path: '/home/itsm/project/html/userApp',
- buildPath: '../unpackage/dist/build/web'
- }
- let Client = require('ssh2-sftp-client');
- function connectSSh() {
- let sftp = new Client();
- sftp.connect({
- host: config.ip,
- port: config.port,
- username: config.username,
- password: config.password
- }).then(() => {
- console.log("-----先执行删除服务器文件-----")
- return sftp.rmdir(config.path, true);
- }).then(() => {
-
- console.log("-----开始上传-----")
- return sftp.uploadDir(path.resolve(__dirname, config.buildPath), config.path);
- }).then((data) => {
- console.log("-----上传完成-----");
- sftp.end();
- }).catch((err) => {
- console.log(err, '-----失败-----');
- sftp.end();
- });
- }
- function runTask() {
-
- connectSSh();
- }
- runTask()
|