FTP Response Stream Parser

1.0.1 · abandoned · verified Sun Apr 19

The `ftp-response-parser` package provides a lightweight, streaming parser specifically designed for handling FTP server response format strings. It efficiently processes incoming FTP protocol messages, including multi-line responses, and emits structured JavaScript objects. Each emitted object includes the numeric status `code`, the full `text` of the response, and boolean flags `isMark` and `isError`. This library is currently at version 1.0.1, with its last update occurring over a decade ago. It functions as a classic Node.js `Stream` and is primarily differentiated by its low-overhead, event-driven approach to parsing continuous streams of FTP data, making it suitable for integration into custom FTP client implementations that require incremental response processing.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to instantiate the `ResponseParser`, listen for `readable` events to process parsed FTP response objects, handle potential errors, and feed it a multi-line FTP response string, ensuring the stream is properly terminated.

const ResponseParser = require('ftp-response-parser');
const myParser = new ResponseParser();

myParser.on('readable', function() {
  let line;
  while ((line = myParser.read()) !== null) {
    console.log(`Code: ${line.code}, Text: ${line.text}`);
  }
});

myParser.on('error', (err) => {
  console.error('Parser encountered an error:', err);
});

myParser.on('end', () => {
  console.log('End of FTP response stream.');
});

// Example FTP multi-line response string
const ftpResponse = `211-Features supported:\n EPRT\n EPSV\n MDTM\n MLST type*;perm*;size*;modify*;unique*;unix.mode;unix.uid;unix.gid;\n REST STREAM\n SIZE\n TVFS\n UTF8\n211 End FEAT.\n215 UNIX Type: L8\n331 Username ok, send password.\n230 Login successful.\n200 Type set to: Binary.\n250 "/test" is the current directory.\n`;

myParser.write(ftpResponse);
myParser.end(); // Signal that no more data will be written

console.log('Parser initialized and example data sent.');

view raw JSON →