|
1 | | -var Parser = require("parse-listing"); |
2 | | -var async = require("async"); |
3 | | - |
4 | | -var RE_RES = /^(\d\d\d)\s(.*)/; |
5 | | -var RE_MULTI = /^(\d\d\d)-/; |
6 | | -var RE_SERVER_RESPONSE = /^(\d\d\d)(.*)/; |
7 | | - |
8 | 1 | var Utils = module.exports = { |
9 | | - /** |
10 | | - * Parse raw output of a file listing, trying in to clean up broken listings |
11 | | - * in the process |
12 | | - * @param {String} listing Raw file listing coming from a 'list' or 'stat' |
13 | | - * @returns {Object[]} |
14 | | - */ |
15 | | - parseEntry: function(listing) { |
16 | | - var t, parsedEntry; |
17 | | - var i = 0; |
18 | | - var parsed = []; |
19 | | - var splitEntries = listing.split(/\r\n|\n/); |
20 | | - async.eachSeries(splitEntries, function(entry, next) { |
21 | | - function _next() { |
22 | | - i += 1; |
23 | | - next(); |
24 | | - } |
25 | | - |
26 | | - // Some servers include an official code-multiline sign at the beginning |
27 | | - // of every string. We must strip it if that's the case. |
28 | | - if (RE_MULTI.test(entry)) |
29 | | - entry = entry.substr(3); |
30 | | - |
31 | | - entry = entry.trim(); |
32 | | - |
33 | | - // Filter file-listing results from 'STAT' command, since they include |
34 | | - // server responses before and after the file listing. |
35 | | - // Issue: https://github.com/sergi/jsftp/issues/3 |
36 | | - if (RE_SERVER_RESPONSE.test(entry) || |
37 | | - RE_RES.test(entry) || RE_MULTI.test(entry)) { |
38 | | - return _next(); |
39 | | - } |
40 | | - |
41 | | - parsedEntry = Parser.parseEntry(entry); |
42 | | - if (parsedEntry === null) { |
43 | | - if (splitEntries[i + 1]) { |
44 | | - t = Parser.parseEntry(entry + splitEntries[i + 1]); |
45 | | - if (t !== null) { |
46 | | - splitEntries[i + 1] = entry + splitEntries[i + 1]; |
47 | | - return _next(); |
48 | | - } |
49 | | - } |
50 | | - |
51 | | - if (splitEntries[i - 1] && parsed.length > 0) { |
52 | | - t = Parser.parseEntry(splitEntries[i - 1] + entry); |
53 | | - if (t !== null) { |
54 | | - parsed[parsed.length - 1] = t; |
55 | | - } |
56 | | - } |
57 | | - } |
58 | | - else if (parsedEntry) { |
59 | | - parsed.push(parsedEntry); |
60 | | - } |
61 | | - _next(); |
62 | | - }); |
63 | | - |
64 | | - return parsed; |
65 | | - }, |
66 | | - |
67 | 2 | getPasvPort: function(text) { |
68 | 3 | var RE_PASV = /([-\d]+,[-\d]+,[-\d]+,[-\d]+),([-\d]+),([-\d]+)/; |
69 | 4 | var match = RE_PASV.exec(text); |
|
0 commit comments