首页 > 解决方案 > sftpConnect:远程主机已重置连接:在使用 ssh2-sftp-client 时在节点 js 中读取 ECONNRESET

问题描述

我试图列出目录中的所有文件,即远程路径。我能够使用它。现在我在使用“listAllFiles”时收到以下错误。

const Client = require("ssh2-sftp-client");
const conn= new Client();

const listAllFiles = () => {
    return new Promise(function (resolve, reject) {
        try {
            conn
                .connect(config)
                .then(() => {
                    console.log("Connected to server .......")
                    return conn.list(remotePath);
                })
                .then((data) => {
                    console.log('Listing directory.........')
                    // console.log(data);
                    filesInDir = data;
                    resolve(filesInDir);
                })
                .then(() => {
                    setTimeout(() => {
                        conn.end();
                    }, 60000);
                   
                })
                .catch((err) => {
                    console.log("error --------------", err.message)                   
                    reject(err.message);
                });
        } catch (error) {
            reject(error);
        }
    });
};

为什么我会得到这个。

RuntimeError: abort(sftpConnect: Remote host has reset the connection: read ECONNRESET). Build with -s ASSERTIONS=1 for more info.

标签: javascriptnode.js

解决方案


推荐阅读