28 lines
688 B
JavaScript
28 lines
688 B
JavaScript
const { NodeSSH } = require('node-ssh');
|
|
const path = require('path');
|
|
const ssh = new NodeSSH();
|
|
|
|
async function uploadFile() {
|
|
try {
|
|
await ssh.connect({
|
|
host: '192.168.104.102',
|
|
username: 'root',
|
|
privateKey: path.resolve(__dirname, 'YI_LIUYANG'), // 私钥文件路径
|
|
});
|
|
|
|
console.log('SSH 连接成功');
|
|
|
|
const localPath = path.resolve(__dirname, 'mock-config.json');
|
|
const remotePath = '/root/mock-config.json'; // 服务器上的目标路径
|
|
|
|
await ssh.putFile(localPath, remotePath);
|
|
console.log('文件上传成功:', remotePath);
|
|
|
|
ssh.dispose();
|
|
} catch (err) {
|
|
console.error('上传失败:', err);
|
|
}
|
|
}
|
|
|
|
uploadFile();
|