我有这个代码通过nodejs使用node-ftp(https://www.npmjs.com/package/ftp)包连接到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' }
FTP通过保持命令连接打开直到客户端(在您的情况下是您的节点程序)关闭它来工作。所以要保持活力。而且,当你不再需要ftp访问时,请记得关闭它。