55 lines
1.2 KiB
JavaScript
55 lines
1.2 KiB
JavaScript
const { Client } = require('ssh2');
|
|
const path = require('path');
|
|
|
|
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;
|
|
}
|
|
|
|
const localFile = path.join(__dirname, 'dist', 'build', 'h5', 'assets', 'list-CHpyn9E7.css');
|
|
const remoteFile = '/www/huishou/dist/build/h5/assets/list-CHpyn9E7.css';
|
|
|
|
sftp.fastPut(localFile, remoteFile, (err) => {
|
|
if (err) {
|
|
console.error('文件上传失败:', err.message);
|
|
conn.end();
|
|
return;
|
|
}
|
|
|
|
console.log('CSS文件上传成功');
|
|
|
|
conn.exec('docker restart huishou', (err, stream) => {
|
|
if (err) {
|
|
console.error('重启容器失败:', err.message);
|
|
conn.end();
|
|
return;
|
|
}
|
|
|
|
stream.on('close', () => {
|
|
console.log('容器已重启');
|
|
conn.end();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
conn.on('error', (err) => {
|
|
console.error('SSH连接错误:', err.message);
|
|
});
|
|
|
|
conn.connect(config); |