65 lines
2.0 KiB
JavaScript
65 lines
2.0 KiB
JavaScript
const { Client } = require('ssh2');
|
|
const fs = require('fs');
|
|
|
|
const config = {
|
|
host: 'hs.yifenbao.cn',
|
|
port: 22,
|
|
username: 'root',
|
|
password: 'Torch1112'
|
|
};
|
|
|
|
const conn = new Client();
|
|
|
|
conn.on('ready', () => {
|
|
console.log('SSH连接成功');
|
|
|
|
conn.sftp((err, sftp) => {
|
|
if (err) {
|
|
console.error('SFTP连接失败:', err.message);
|
|
conn.end();
|
|
return;
|
|
}
|
|
|
|
// 上传index.html
|
|
console.log('上传index.html...');
|
|
sftp.fastPut('./dist/build/h5/index.html', '/www/huishou/dist/build/h5/index.html', (err) => {
|
|
if (err) console.error('index.html上传失败:', err.message);
|
|
else console.log('index.html上传成功');
|
|
|
|
// 上传CSS
|
|
console.log('上传CSS...');
|
|
sftp.fastPut('./dist/build/h5/assets/list-CHpyn9E7.css', '/www/huishou/dist/build/h5/assets/list-CHpyn9E7.css', (err) => {
|
|
if (err) console.error('CSS上传失败:', err.message);
|
|
else console.log('CSS上传成功');
|
|
|
|
// 上传JS
|
|
console.log('上传JS...');
|
|
sftp.fastPut('./dist/build/h5/assets/pages-order-list.Oq2uWnRW.js', '/www/huishou/dist/build/h5/assets/pages-order-list.Oq2uWnRW.js', (err) => {
|
|
if (err) console.error('JS上传失败:', err.message);
|
|
else console.log('JS上传成功');
|
|
|
|
// 上传index.js
|
|
console.log('上传index.js...');
|
|
sftp.fastPut('./dist/build/h5/assets/index-C79DJQTa.js', '/www/huishou/dist/build/h5/assets/index-C79DJQTa.js', (err) => {
|
|
if (err) console.error('index.js上传失败:', err.message);
|
|
else console.log('index.js上传成功');
|
|
|
|
// 重启容器
|
|
conn.exec('docker restart huishou', (err, stream) => {
|
|
stream.on('close', () => {
|
|
console.log('容器已重启');
|
|
conn.end();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
conn.on('error', (err) => {
|
|
console.error('SSH连接错误:', err.message);
|
|
});
|
|
|
|
conn.connect(config); |