任何人都可以帮助我,如何在 node js 中使用 node-ssh 模块断开 ssh 连接。还有如何处理错误。
我的代码是
driver = require('node-ssh');
ssh = new driver({
host: '192.168.*.*',
username: 'user',
password: 'password',
privateKey : require('fs').readFileSync('/tmp/my_key')
});
ssh.connect().then(function() {
/*
some code
*/
},function(error) {
console.log(error);
});
请帮忙。
最佳答案
使用dispose
方法。示例:
const node_ssh = require('node-ssh');
const ssh = new node_ssh();
ssh.connect({
host: 'XXX',
username: 'YYY',
privateKey: 'ZZZ'
}).then(resp => {
console.log(resp);
ssh.dispose();
});
关于node.js - 如何在node js中使用node-ssh断开ssh连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30392921/