const { Client } = require('ssh2'); 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; } sftp.fastPut('./dist/build/h5/assets/pages-index-index.Dfg3o6TQ.js', '/www/huishou/dist/build/h5/assets/pages-index-index.Dfg3o6TQ.js', (err) => { if (err) { console.error('文件上传失败:', err.message); conn.end(); return; } console.log('文件上传成功'); 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);