New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

basic-ftp

Package Overview
Dependencies
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

basic-ftp - npm Package Compare versions

Comparing version 2.5.1 to 2.5.2

test/parseControlResponseSpec.js

5

CHANGELOG.md
# Changelog
## 2.5.2
- Don't report unexpected positive completion codes as errors.
- Improve documentation.
## 2.5.1

@@ -4,0 +9,0 @@

51

lib/ftp.js

@@ -169,11 +169,10 @@ "use strict";

response = this._partialResponse + response;
// Parse as response groups.
const grouped = groupControlResponse(response);
// Remember any remainder.
this._partialResponse = grouped.rest;
const parsed = parseControlResponse(response);
// Remember any incomplete remainder.
this._partialResponse = parsed.rest;
// Each response group is passed along individually.
grouped.groups.forEach(message => {
for (const message of parsed.messages) {
const code = parseInt(message.substr(0, 3), 10);
this._respond({ code, message });
});
this._respond({ code, message });
}
}

@@ -280,3 +279,3 @@

return this.ftp.handle(undefined, (res, task) => {
if (res.code === 220) {
if (positiveCompletion(res.code)) {
task.resolve(res);

@@ -321,3 +320,3 @@ }

return this.ftp.handle(command, (res, task) => {
if (res.code === 200 || res.code === 234) {
if (positiveCompletion(res.code)) {
upgradeSocket(this.ftp.socket, options).then(tlsSocket => {

@@ -345,3 +344,3 @@ this.ftp.log("Control socket is using " + tlsSocket.getProtocol());

return this.ftp.handle("USER " + user, (res, task) => {
if (res.code === 230 || res.code === 202) { // User logged in proceed OR Command superfluous
if (positiveCompletion(res.code)) { // User logged in proceed OR Command superfluous
task.resolve(res);

@@ -632,3 +631,3 @@ }

upgradeSocket,
groupControlResponse,
parseControlResponse,
TransferResolver

@@ -638,2 +637,6 @@ }

function positiveCompletion(code) {
return code >= 200 && code < 300;
}
/**

@@ -671,3 +674,3 @@ * Upgrade a socket connection.

return ftp.handle("PASV", (res, task) => {
if (res.code === 227) {
if (positiveCompletion(res.code)) {
const target = parseIPv4PasvResponse(res.message);

@@ -742,3 +745,3 @@ if (!target) {

}
else if (res.code === 226 || res.code === 250) { // Transfer complete
else if (positiveCompletion(res.code)) { // Transfer complete
resolver.confirm(task);

@@ -775,3 +778,3 @@ }

}
else if (res.code === 226 || res.code === 250) { // Transfer complete
else if (positiveCompletion(res.code)) { // Transfer complete
resolver.resolve(task, res.code);

@@ -807,3 +810,3 @@ }

}
else if (res.code === 226 || res.code === 250) { // Transfer complete
else if (positiveCompletion(res.code)) { // Transfer complete
resolver.resolve(task, res.code);

@@ -827,5 +830,5 @@ }

/**
* Parse an FTP response as response groups. A response group is a complete single- or
* multiline response. An FTP response can also contain multiple multiline responses
* that will each be represented by a response group. A response can also be incomplete
* Parse an FTP control response as a collection of messages. A message is a complete
* single- or multiline response. A response can also contain multiple multiline responses
* that will each be represented by a message. A response can also be incomplete
* and be completed on the next incoming data chunk for which case this function also

@@ -835,7 +838,7 @@ * describes a `rest`. This function converts all CRLF to LF.

* @param {string} text
* @returns {{groups: string[], rest: string}}
* @returns {{messages: string[], rest: string}}
*/
function groupControlResponse(text) {
function parseControlResponse(text) {
const lines = text.split(/\r?\n/);
const groups = [];
const messages = [];
let startAt = 0;

@@ -854,3 +857,3 @@ let token = "";

// Single lines can be grouped immediately.
groups.push(line);
messages.push(line);
}

@@ -861,3 +864,3 @@ }

token = "";
groups.push(lines.slice(startAt, i + 1).join("\n"));
messages.push(lines.slice(startAt, i + 1).join("\n"));
}

@@ -867,3 +870,3 @@ }

const rest = token !== "" ? lines.slice(startAt).join("\n") + "\n" : "";
return { groups, rest };
return { messages, rest };
}

@@ -870,0 +873,0 @@

{
"name": "basic-ftp",
"version": "2.5.1",
"version": "2.5.2",
"description": "FTP/FTPS client library",

@@ -25,5 +25,5 @@ "main": "./lib/ftp",

"devDependencies": {
"eslint": "^4.15.0",
"mocha": "^4.1.0"
"eslint": "^4.16.0",
"mocha": "^5.0.0"
}
}

@@ -11,3 +11,3 @@ # Basic FTP

FTP is an old protocol, there are many features, quirks and server implementations. It's not a goal to support all of them but it should be possible for you to solve your specific issues without changing the library.
FTP is an old protocol, there are many features, quirks and server implementations. It's not a goal to support all of them. Instead, it should be possible for you to solve your specific issues without changing the library.

@@ -47,3 +47,3 @@ ## Dependencies

Here is another example showing how to recursively remove all files and directories. It also shows that not all FTP commands are backed by a method. A similar function is already part of the Client API.
Here is another example showing how to recursively remove all files and directories. It also shows that not all FTP commands are backed by a method.

@@ -82,3 +82,3 @@ ```js

Upgrade the existing control connection with TLS. You may provide options that are the same you'd use for `tls.connect()` in NodeJS. For example `rejectUnauthorized: false` if you must. Call this function before you log in. Subsequently created data connections will automatically be upgraded to TLS.
Upgrade the existing control connection with TLS. You may provide options that are the same you'd use for [tls.connect()](https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener) in NodeJS. Remember to upgrade before you log in. Subsequently created data connections will automatically be upgraded to TLS.

@@ -95,3 +95,3 @@ `login(user = "anonymous", password = "guest")`

Send an FTP command. You can optionally choose to ignore error return codes. Other errors originating from the socket connections including timeouts will still throw an exception.
Send an FTP command. You can choose to ignore error return codes. Other errors originating from the socket connections including timeouts will still reject the Promise returned.

@@ -146,7 +146,7 @@ `cd(remotePath)`

You can provide a custom function that prepares the data connection for a transfer. FTP uses a dedicated socket connection for each single data transfer. Data transfers include directory listings, file uploads and downloads. This property holds the function that prepares this connection. Right now the library only offers Passive Mode over IPv4. The signature of the function is `(ftp: FTPContext) => Promise<void>`. The section below about extending functionality explains what `FTPContext` is.
You can provide a custom function that prepares the data connection for a transfer. FTP uses a dedicated socket connection for each single data transfer. Data transfers include directory listings, file uploads and downloads. This property holds the function that prepares this connection. Right now the library only offers Passive Mode over IPv4. The signature of the function is `(ftp: FTPContext) => Promise<void>` and its job is to set `ftp.dataSocket`. The section below about extending functionality explains what `FTPContext` is.
`get/set client.parseList`
You can provide a custom parser to parse directory listing data, for example to support the DOS format. This library only supports the Unix and DOS formats for now. Parsing these list responses is a central part of every FTP client because there is no standard that all servers adhere to. The signature of the function is `(rawList: string) => FileInfo[]`. `FileInfo` is also exported by the library.
You can provide a custom parser to parse directory listing data. This library only supports Unix and DOS formats out-of-the-box. Parsing these list responses is a central part of every FTP client because there is no standard that all servers adhere to. The signature of the function is `(rawList: string) => FileInfo[]`. `FileInfo` is also exported by the library.

@@ -157,3 +157,3 @@ ## Extend

The client described above is just a collection of convenience functions using an underlying `FTPContext`. An FTPContext provides the foundation to write an FTP client. It holds the socket connections and provides an API to handle responses and simplifies event handling. Through `client.ftp` you get access to this context.
The `Client` described above is just a collection of convenience functions using an underlying `FTPContext`. An FTPContext provides the foundation to write an FTP client. It holds the socket connections and provides an API to handle responses and events in a simplified way. Through `client.ftp` you get access to this context.

@@ -160,0 +160,0 @@ ### FTPContext API

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc