Javascript 如何在nodejs中列出ftp文件?

Javascript 如何在nodejs中列出ftp文件?,javascript,node.js,ftp,Javascript,Node.js,Ftp,我有这段代码,可以使用node ftp()包通过nodejs连接到ftp服务器 节点版本:v10.13.0 我试图将下一行改为false socket.setKeepAlive(true); 您正在控制台上打印的消息如下: [connection] < '220-FileZilla Server version 0.9.41 beta\r\n' [connection] < '220 Welcome to ComexPerú FTP Server\r\n' [parser] &l

我有这段代码,可以使用node ftp()包通过nodejs连接到ftp服务器

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

socket.setKeepAlive(true);
您正在控制台上打印的消息如下:

[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' }

[连接]<'220 FileZilla服务器版本0.9.41 beta\r\n'
[连接]<'220欢迎使用ComexPer::FTP服务器\r\n'
[解析器]<'220 FileZilla服务器版本0.9.41 beta\r\n220欢迎使用ComexPer:'FTP服务器\r\n'
[parser]响应:code=220,buffer='FileZilla服务器版本0.9.41 beta\r\n欢迎来到ComexPerÃ:FTP服务器'
[连接]>“用户用户名”
[连接]<“用户名需要331密码\r\n”
[语法分析器]<“用户名需要331密码\r\n”
[parser]响应:code=331,buffer='username需要密码'
[连接]>“通过”
[连接]<'230已登录\r\n'
[分析器]<'230已登录\r\n'
[parser]响应:code=230,buffer='Logged on'
[连接]>“壮举”
[连接]<'211功能:\r\n'
[连接]<'MDTM\r\n REST流\r\n大小\r\n MLST类型*;大小*;修改*\r\n MLSD\r\n'
[连接]<'UTF8\r\n CLNT\r\n MFMT\r\n'
[连接]<'211结束\r\n'
[解析器]<'211功能:\r\n MDTM\r\n REST流\r\n大小\r\n MLST类型*;大小*;修改*\r\n MLSD\r\n UTF8\r\n CLNT\r\n MFMT\r\n211 End\r\n'
[parser]响应:code=211,buffer='Features:\r\n MDTM\r\n REST STREAM\r\n SIZE\r\n MLST type*;大小*;修改*\r\n MLSD\r\n UTF8\r\n CLNT\r\n MFMT\r\n
[连接]>“类型I”
[连接]<'200类型设置为I\r\n'
[分析器]<'200类型设置为I\r\n'
[parser]响应:code=200,buffer='Type设置为I'
[连接]>“PASV”
{错误:读取EconReset
在TCP.onStreamRead(internal/stream_base_commons.js:111:27)处,errno:'ECONNRESET',code:'ECONNRESET',syscall:'read'}

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

连接的参数为:socket.setTimeout(0);socket.setKeepAlive(true);错误依然存在。
[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' }