繁体   English   中英

节点 ssh2:类型错误:<Object> 不是构造函数

[英]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崩溃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
    });

尽管您已经在问题中分享了它,但您应该检查如何使用它的文档。 我建议你通过它一次。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM