basic-ftp
Advanced tools
Comparing version 2.4.2 to 2.5.0
# Changelog | ||
## 2.5.0 | ||
- Add support for DOS-style directory listing. | ||
- Select a compatible directory listing parser automatically. | ||
- Throw an exception with a detailed description if the directory listing can't be parsed. | ||
## 2.4.2 | ||
@@ -4,0 +10,0 @@ |
@@ -8,3 +8,3 @@ "use strict"; | ||
const promisify = require("util").promisify; | ||
const parseListUnix = require("./parseListUnix"); | ||
const defaultParseList = require("./parseList"); | ||
const FileInfo = require("./FileInfo"); | ||
@@ -247,3 +247,3 @@ | ||
this.prepareTransfer = enterPassiveModeIPv4; | ||
this.parseList = parseListUnix; | ||
this.parseList = defaultParseList; | ||
} | ||
@@ -630,4 +630,2 @@ | ||
upgradeSocket, | ||
parseListUnix, | ||
enterPassiveModeIPv4, | ||
groupControlResponse, | ||
@@ -727,3 +725,3 @@ TransferResolver | ||
*/ | ||
function list(ftp, parseList = parseListUnix) { | ||
function list(ftp, parseList = defaultParseList) { | ||
const resolver = new TransferResolver(ftp); | ||
@@ -730,0 +728,0 @@ let rawList = ""; |
"use strict"; | ||
const FileInfo = require("./FileInfo"); | ||
/** | ||
@@ -7,23 +9,6 @@ * This parser is based on the FTP client library source code in Apache Commons Net provided | ||
* | ||
* @see http://svn.apache.org/viewvc/commons/proper/net/tags/NET_3_6/src/main/java/org/apache/commons/net/ftp/parser/ | ||
*/ | ||
const FileInfo = require("./FileInfo"); | ||
/** | ||
* Parses raw list data as a Unix listing. | ||
* @param {string} rawList | ||
* @returns {FileInfo[]} | ||
*/ | ||
module.exports = function(rawList) { | ||
return rawList.split(/\r?\n/) | ||
// Strip possible multiline prefix | ||
.map(line => (/^(\d\d\d)-/.test(line)) ? line.substr(3) : line) | ||
.map(parseLine) | ||
.filter(fileRef => fileRef !== undefined); | ||
}; | ||
/** | ||
* This is the regular expression used by this parser. | ||
* http://svn.apache.org/viewvc/commons/proper/net/tags/NET_3_6/src/main/java/org/apache/commons/net/ftp/parser/ | ||
* | ||
* Below is the regular expression used by this parser. | ||
* | ||
* Permissions: | ||
@@ -95,3 +80,8 @@ * r the file is readable | ||
function parseLine(line) { | ||
exports.testLine = function(line) { | ||
// Example: "-rw-r--r--+ 1 patrick staff 1057 Dec 11 14:35 test.txt" | ||
return line !== undefined && line.match(RE_LINE) !== null; | ||
}; | ||
exports.parseLine = function(line) { | ||
const groups = line.match(RE_LINE); | ||
@@ -166,2 +156,2 @@ if (groups) { | ||
return undefined; | ||
} | ||
}; |
{ | ||
"name": "basic-ftp", | ||
"version": "2.4.2", | ||
"version": "2.5.0", | ||
"description": "FTP/FTPS client library", | ||
@@ -5,0 +5,0 @@ "main": "./lib/ftp", |
@@ -9,5 +9,5 @@ # Basic FTP | ||
This library has two goals: Provide a solid foundation that covers the usual needs and make it easy to extend functionality if necessary. | ||
This library has two goals: Provide a solid foundation that covers the usual needs and make it easy for the user to extend functionality if necessary. | ||
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 easy 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 but it should be possible for you to solve your specific issues without changing the library. | ||
@@ -47,15 +47,15 @@ ## Dependencies | ||
Here is another example to show how to compose more complex operations like recursively removing all files and directories. This 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. A similar function is already part of the Client API. | ||
```js | ||
async clearWorkingDir() { | ||
for (const file of await this.list()) { | ||
async clearWorkingDir(client) { | ||
for (const file of await client.list()) { | ||
if (file.isDirectory) { | ||
await this.cd(file.name); | ||
await this.clearWorkingDir(); | ||
await this.send("CDUP"); | ||
await this.send("RMD " + file.name); | ||
await client.cd(file.name); | ||
await clearWorkingDir(client); | ||
await client.send("CDUP"); | ||
await client.send("RMD " + file.name); | ||
} | ||
else { | ||
await this.send("DELE " + file.name); | ||
await client.send("DELE " + file.name); | ||
} | ||
@@ -110,3 +110,3 @@ } | ||
List files and directories in the current working directory. | ||
List files and directories in the current working directory. Currently, this library only supports Unix-style directory listings. | ||
@@ -113,0 +113,0 @@ `upload(readableStream, remoteFilename)` |
89958
16
1332