Failed to connect: Error: connect: getConnection: All configured authentication methods failed

861 views Asked by At

I develop a function for my bot discord, and I want to connect to a sftp server with the module ssh2-sftp-client. For my project, I have several directories, but for my case, I only need to give you 2, in the folder "functions", there are two files, sftpConnection.js and react.js, and in the folder "events", there is the file messageCreate.js, messageCreate is used to call the react.js file, which has the function sftpScrapper, which is used to use sftpConnection, where there is a class SFTPClient, which is used to connect to a sftp server. The problem is that when I try to make the sftp connection, my console tells me the error:

Connecting to "hostName":22
Failed to connect: Error: connect: getConnection: All configured authentication methods failed
    at SftpClient.fmtError (E:\Perso\PHOTOSHOP\CODING\discord.js v14\Lt-Col. Tanya\node_modules\ssh2-sftp-client\src\index.js:111:22)
    at SftpClient.connect (E:\Perso\PHOTOSHOP\CODING\discord.js v14\Lt-Col. Tanya\node_modules\ssh2-sftp-client\src\index.js:249:37)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async SFTPClient.connect (E:\Perso\PHOTOSHOP\CODING\discord.js v14\Lt-Col. Tanya\functions\sftpConnection.js:10:13)
    at async Object.sftpScraper (E:\Perso\PHOTOSHOP\CODING\discord.js v14\Lt-Col. Tanya\functions\react.js:259:17)
    at async module.exports (E:\Perso\PHOTOSHOP\CODING\discord.js v14\Lt-Col. Tanya\events\messageCreate.js:21:5) {
  code: 'ERR_GENERIC_CLIENT',
  custom: true
}
node:events:491
      throw er; // Unhandled 'error' event
      ^

    at Object.sftpScraper (E:\Perso\PHOTOSHOP\CODING\discord.js v14\Lt-Col. Tanya\functions\react.js:266:34)
    at async module.exports (E:\Perso\PHOTOSHOP\CODING\discord.js v14\Lt-Col. Tanya\events\messageCreate.js:21:5)
Emitted 'error' event on Client instance at:
    at emitUnhandledRejectionOrErr (node:events:394:10)
    at process.processTicksAndRejections (node:internal/process/task_queues:84:21)

Node.js v18.10.0
[nodemon] app crashed - waiting for file changes before starting...```

The code :

sftpConnection.js :

const ssh = require("ssh2-sftp-client")

class SFTPClient {
    constructor() {
        this.client = new ssh();
    }
    async connect(options) {
        console.log(`Connecting to ${options.host}:${options.port}`);
        try {
            await this.client.connect(options);
        } catch (err) {
            console.log('Failed to connect:', err);
        }
    }
    
    async disconnect() {
        await this.client.end();
    }

    async listFiles(remoteDir, fileGlob) {
        console.log(`Listing ${remoteDir} ...`);
        let fileObjects;
        try {
          fileObjects = await this.client.list(remoteDir, fileGlob);
        } catch (err) {
          console.log('Listing failed:', err);
        }
      
        const fileNames = [];
      
        for (const file of fileObjects) {
          if (file.type === 'd') {
            console.log(`${new Date(file.modifyTime).toISOString()} PRE ${file.name}`);
          } else {
            console.log(`${new Date(file.modifyTime).toISOString()} ${file.size} ${file.name}`);
          }
      
          fileNames.push(file.name);
        }
      
        return fileNames;
      }

};

module.exports = SFTPClient```

react.js :

const Discord = require("discord.js");
const { connect } = require("http2");
const fs = require("fs");
// const fetch = require('node-fetch');
// const config = require("../Storage/config.json");
const https = require('https');
const sftp = require("./sftpConnection.js");
const sftpLog = require("../Storage/sftpLog.json");
const SFTPClient = require("./sftpConnection.js");
// const { client } = require("tenorjs");

var functions = {
sftpScraper: async function(bot, message) {
switch (message.content) {
case "test-sftp":
const {hostCharon, ipCharon, usernameCharon, passwordCharon} = sftpLog\["piccoma-charon"\]\[0\];
const {hostMakma, ipMakma, usernameMakma, passwordMakma} = sftpLog\["piccoma-makma"\]\[0\]

                const sftpClient = new SFTPClient();
                
                await sftpClient.connect({
                    host: hostCharon,
                    port: "22",
                    username: usernameCharon,
                    passwordCharon: passwordCharon,
                    tryKeyboard: true,
                })
    
                await sftpClient.listFiles(".");
                
                break;
        
            default:
                break;
        }
        
    }

}

module.exports = functions;```

and the react.js is launched on messageCreate.js :

const config = require("../Storage/config.json");
module.exports = async(bot, message) => {
    ; const prefix = config.prefix;
    const owners = [''];
    const wompServer = ['']
    bot.user.setActivity(""); // Marque en status ""

    const args = message.content.split(/ +/g);
    const command = args.shift().slice(prefix.length).toLowerCase();
    const cmd = bot.commands.get(command) || bot.aliases.get(command);

    const reactFunction = require('../functions/react.js');
    await reactFunction.fakeGift(bot, message);
    await reactFunction.sftpScraper(bot, message);
cmd.run(bot, message, args).catch(e => { return console.log(e) });

    bot.logger.log(`[${message.member.user.tag}] a utilisé la commande [${cmd.help.name}]`).catch(e => { return console.log(e) });

    message.delete()

}```

I've tried to put a tryKeyboard: true, but i don't know how to use it, and the methode i have seen, doesn't work for me, because i can't do a sftpClient.on()...

Can you propose to me a way to fix this problem which work with my code ?

0

There are 0 answers