Node ssh2: TypeError: <Object> is not a constructor
Node ssh2: TypeError: <Object> is not a constructor
我有节点 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
});
我似乎无法弄清楚是什么原因造成的。
我认为你应该这样做,你获取实例的方式不正确。
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
});
尽管您已经在问题中分享了它,但您应该查看如何使用它的文档。我建议你看一遍。
我有节点 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
});
我似乎无法弄清楚是什么原因造成的。
我认为你应该这样做,你获取实例的方式不正确。
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
});
尽管您已经在问题中分享了它,但您应该查看如何使用它的文档。我建议你看一遍。