簡體   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