我有node v14.17.0和ssh2 1.1.0 https://www.npmjs.com/package/ssh2
我尝试使用下面的代码进行连接,但它在TypeError: NodeSSH is not a constructor上崩溃
我也试过
var NodeSSH= require('ssh2');
var c = new NodeSSH();和
var NodeSSH= require('ssh2').Client;和
const {NodeSSH} = require('ssh2');
const c = new NodeSSH();
c.on('keyboard-interactive', function(name, instructions, instructionsLang, prompts, finish) {
console.log('Connection :: keyboard-interactive');
finish(['pswd']);
}).on('end', function() {
console.log('Connection :: end');
console.log(callback());
}).on('error', function(error) {
console.log(error);
}).connect({
host: 'XX.XX.XXX.XXX',
username: 'usr',
port: "22",
tryKeyboard: true,
debug: console.log
});我似乎找不出是什么原因造成的。
发布于 2021-07-21 15:01:53
我认为你应该这样做,你获取实例的方式是不正确的。
const { Client } = require('ssh2'); // it exports Client not NodeSSH
const conn = new Client();
conn.on('keyboard-interactive', function(name, instructions, instructionsLang, prompts, finish) {
console.log('Connection :: keyboard-interactive');
finish(['pswd']);
}).on('end', function() {
console.log('Connection :: end');
console.log(callback());
}).on('error', function(error) {
console.log(error);
}).connect({
host: 'XX.XX.XXX.XXX',
username: 'usr',
port: "22",
tryKeyboard: true,
debug: console.log
});你应该检查文档如何使用它,尽管你已经在问题中分享了它。我建议你再看一遍。
https://stackoverflow.com/questions/68465029
复制相似问题