const { NodeSSH } = require("node-ssh"); const os = require("node:os"); const config = { host: "192.168.2.250", username: "admin", privateKeyPath: `${os.homedir()}\\.ssh\\id_rsa_2048`, localDirectory: "dist", remoteDirectory: "/D:/nginx/nginx-1.27.1/erp", }; async function main() { const ssh = new NodeSSH(); await ssh.connect({ host: config.host, username: config.username, privateKeyPath: config.privateKeyPath, }); const res = await ssh.putDirectory( config.localDirectory, config.remoteDirectory, { recursive: true, } ); if (res) { console.log("传输完成", res); } else { console.error(res); } const connection = ssh.getConnection(); connection.destroy(); // await ssh.dispose(); } main();