【问题标题】:how to list ftp files in nodejs?如何在nodejs中列出ftp文件?
【发布时间】:2019-04-04 21:14:42
【问题描述】:

我有这段代码可以使用 node-ftp (https://www.npmjs.com/package/ftp) 包通过 nodejs 连接到 ftp 服务器。

节点版本:v10.13.0 我试图将下一行更改为 false。

socket.setKeepAlive(true);
var Client = require('ftp');
const fs = require('fs');
const moment = require('moment');

var c = new Client();
var date;
var filename;
c.on('error', (err) => console.log(err));

c.on('ready', function() {

    c.list((err, list) => {
        if (err) console.dir(err);
        console.dir(list);
        c.end();
    });

});

c.connect({ host: 'hostname', user: 'username', password: 'pass', debug: console.log.bind(console) });

您在控制台上打印的消息如下:

[connection] < '220-FileZilla Server version 0.9.41 beta\r\n'
[connection] < '220 Welcome to ComexPerú FTP Server\r\n'
[parser] < '220-FileZilla Server version 0.9.41 beta\r\n220 Welcome to ComexPerú FTP Server\r\n'
[parser] Response: code=220, buffer='FileZilla Server version 0.9.41 beta\r\nWelcome to ComexPerú FTP Server'
[connection] > 'USER username'
[connection] < '331 Password required for username\r\n'
[parser] < '331 Password required for username\r\n'
[parser] Response: code=331, buffer='Password required for username'
[connection] > 'PASS pass'
[connection] < '230 Logged on\r\n'
[parser] < '230 Logged on\r\n'
[parser] Response: code=230, buffer='Logged on'
[connection] > 'FEAT'
[connection] < '211-Features:\r\n'
[connection] < ' MDTM\r\n REST STREAM\r\n SIZE\r\n MLST type*;size*;modify*;\r\n MLSD\r\n'
[connection] < ' UTF8\r\n CLNT\r\n MFMT\r\n'
[connection] < '211 End\r\n'
[parser] < '211-Features:\r\n MDTM\r\n REST STREAM\r\n SIZE\r\n MLST type*;size*;modify*;\r\n MLSD\r\n UTF8\r\n CLNT\r\n MFMT\r\n211 End\r\n'
[parser] Response: code=211, buffer='Features:\r\n MDTM\r\n REST STREAM\r\n SIZE\r\n MLST type*;size*;modify*;\r\n MLSD\r\n UTF8\r\n CLNT\r\n MFMT\r\nEnd'
[connection] > 'TYPE I'
[connection] < '200 Type set to I\r\n'
[parser] < '200 Type set to I\r\n'
[parser] Response: code=200, buffer='Type set to I'
[connection] > 'PASV'

{ Error: read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:111:27) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' }

【问题讨论】:

    标签: javascript node.js ftp


    【解决方案1】:

    FTP 通过保持命令连接打开直到客户端(在您的情况下是您的节点程序)关闭它来工作。所以一定要让它活着。而且,当您不再需要 ftp 访问权限时,请记得关闭它。

    【讨论】:

    • 连接的参数为:socket.setTimeout(0); socket.setKeepAlive(true);错误依旧。
    猜你喜欢
    • 2020-05-03
    • 2023-01-27
    • 2021-05-22
    • 2012-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-28
    • 1970-01-01
    相关资源
    最近更新 更多