Comparing version 0.0.9 to 0.1.0
@@ -252,3 +252,3 @@ /* | ||
">test get fileList array": function(next) { | ||
"test get fileList array": function(next) { | ||
var ftp = this.ftp; | ||
@@ -255,0 +255,0 @@ var file1 = "testfile.txt"; |
13
jsftp.js
@@ -429,4 +429,3 @@ /* | ||
* Downloads a file from FTP server, given a valid Path. It uses the RETR | ||
* command to retrieve the file. the `get` and `retr` methods are synonymous of | ||
* this method. | ||
* command to retrieve the file. | ||
*/ | ||
@@ -491,4 +490,12 @@ this.get = function(filePath, callback) { | ||
this.ls = function(filePath, callback) { | ||
var self = this; | ||
this.raw.stat(filePath, function(err, data) { | ||
entriesToList(err, data.text); | ||
// We might be connnected to a server that doesn't support the | ||
// 'STAT' command. We use 'LIST' instead. | ||
if (err && data.code === 502) | ||
self.list(filePath, function(err, data) { | ||
entriesToList(err, data.text) | ||
}); | ||
else | ||
entriesToList(err, data.text); | ||
}); | ||
@@ -495,0 +502,0 @@ |
@@ -20,44 +20,2 @@ /* | ||
"test parseResponses function" : function(next) { | ||
var res1 = [ | ||
"211 End of status", | ||
"123-First line", | ||
"Second line", | ||
"234 A line beginning with numbers", | ||
"123 The last line" | ||
]; | ||
var res2 = [ | ||
"221-You have transferred 271165 bytes in 1 files.", | ||
"221-Total traffic for this session was 271859 bytes in 1 transfers.", | ||
"221 Thank you for using the FTP service on server.example.com." | ||
]; | ||
assert.throws( | ||
function() { | ||
Parser.parseResponses("211 End of status"); | ||
}, | ||
TypeError | ||
); | ||
var response = Parser.parseResponses(res1); | ||
assert.ok(response[0][0] === 211); | ||
assert.ok(response[0][1] === " End of status"); | ||
assert.ok(response[1][0] === 123); | ||
assert.ok(response[1][1] === | ||
"-First line\nSecond line\n234 A line beginning with numbers\n123 The last line"); | ||
var response2 = Parser.parseResponses(res2); | ||
assert.ok(response2[0][0] === 221); | ||
assert.ok(response2[0][1] === | ||
"-You have transferred 271165 bytes in 1 files.\n" + | ||
"221-Total traffic for this session was 271859 bytes in 1 transfers.\n" + | ||
"221 Thank you for using the FTP service on server.example.com."); | ||
next(); | ||
}, | ||
"test ftp unix LIST responses" : function(next) { | ||
@@ -79,3 +37,3 @@ var str = "211-Status of /:\r\n\ | ||
drwxr-xr-x 10 mrclash pg223090 4096 Aug 3 2009 svn\r\n\ | ||
-rwxr-xr-x 1 mrclash pg223090 76 Aug 9 14:47 sync-alpine.sh\n\ | ||
-rwxr-xr-x 1 mrclash pg223090 76 Aug 9 14:47 sync-alpine.sh\r\n\ | ||
drwxr-xr-x 2 mrclash pg223090 4096 Aug 4 10:00 test_c9\r\n\ | ||
@@ -419,27 +377,2 @@ -rw-r--r-- 1 mrclash pg223090 4 Aug 4 09:11 testfile.txt\r\n\ | ||
/* | ||
unixEntries.forEach(function(entry) { | ||
var result = Parser.entryParser(entry.line); | ||
assert.equal(result.type, entry.type); | ||
assert.equal(result.size, entry.size); | ||
assert.equal(result.name, entry.name); | ||
assert.equal(result.time, entry.time); | ||
assert.equal(result.owner, entry.owner); | ||
assert.equal(result.group, entry.group); | ||
assert.equal(entry.userReadPerm, result.userPermissions.read); | ||
assert.equal(entry.userWritePerm, result.userPermissions.write); | ||
assert.equal(entry.userExecPerm, result.userPermissions.exec); | ||
assert.equal(entry.groupReadPerm, result.groupPermissions.read); | ||
assert.equal(entry.groupWritePerm, result.groupPermissions.write); | ||
assert.equal(entry.groupExecPerm, result.groupPermissions.exec); | ||
assert.equal(entry.otherReadPerm, result.otherPermissions.read); | ||
assert.equal(entry.otherWritePerm, result.otherPermissions.write); | ||
assert.equal(entry.otherExecPerm, result.otherPermissions.exec); | ||
}); | ||
*/ | ||
next(); | ||
@@ -446,0 +379,0 @@ }, |
@@ -96,85 +96,3 @@ /** | ||
/** | ||
* Parses standard FTP replies. Please note that this only involves replies in | ||
* the form of <code> <message>. It doesn't parse file listings or non-standard | ||
* extensions. | ||
* | ||
* @param lines {Array} FTP entries (responses) | ||
* @returns {Array} Processed entries | ||
*/ | ||
exports.parseResponses = function(lines) { | ||
if (!Array.isArray(lines)) | ||
throw new TypeError("The parameter should be an Array"); | ||
var responses = []; | ||
compact(lines).map(function(line) { | ||
var match = line.match(RE_SERVER_RESPONSE); | ||
match && (line = [parseInt(match[1], 10), match[2]]); | ||
return line; | ||
}) | ||
.reduce(function(p, c, i) { | ||
// If there is a previous line it means that we are inside a multiline | ||
// server response command, in which case we will add the current | ||
// line contents to the previous one, but we have to check if the | ||
// current line is the one that terminates the multiline string, in | ||
// which case we add its contents and terminate the multiline by | ||
// returning null. | ||
if (p) { | ||
var cIsMultiLine, currentMsg; | ||
var cIsArray = Array.isArray(c); | ||
if (cIsArray) { | ||
cIsMultiLine = c[1][0] == "-"; | ||
currentMsg = c[0] + c[1]; | ||
} | ||
else { | ||
cIsMultiLine = false; | ||
currentMsg = c; | ||
} | ||
p[1] += "\n" + currentMsg; | ||
// If the current line is a code/message response, and the code | ||
// is the same as the previous code and the current line is not | ||
// a multiline one (in which case it would be treated as any | ||
// random text). | ||
if (cIsArray && c[0] == p[0] && !cIsMultiLine) { | ||
responses.push(p); | ||
return null; | ||
} | ||
return p; | ||
} | ||
else if (c[1].charAt(0) == "-") { | ||
return c; | ||
} | ||
else { | ||
responses.push(c); | ||
return null; | ||
} | ||
}, null); | ||
return responses; | ||
}; | ||
exports.processDirLines = function(lines, type) { | ||
var processed = []; | ||
var t; | ||
lines.forEach(function(line) { | ||
if (line.length) { | ||
if (type === "LIST") { | ||
var result = exports.entryParser(line); | ||
if (result) { | ||
var t = typeof result == "string" ? "raw" : "entry"; | ||
processed.push([t, result, line]); | ||
} | ||
} | ||
//else if (type === 'MLSD') | ||
//result = parseMList(lines[i], numFields); | ||
} | ||
}); | ||
return processed; | ||
}; | ||
/** | ||
* Selects which parser to use depending on the first character of the line to | ||
@@ -230,6 +148,6 @@ * parse. | ||
var pos = name.indexOf(' -> '); | ||
if (pos > -1) { | ||
name = name.substring(0, pos); | ||
target = name.substring(pos + 4); | ||
var isLink = /(.*)\s->\s(.*)/.exec(name); | ||
if (isLink) { | ||
name = isLink[1]; | ||
target = isLink[2]; | ||
} | ||
@@ -236,0 +154,0 @@ |
{ | ||
"name": "jsftp", | ||
"id": "jsftp", | ||
"version": "0.0.9", | ||
"version": "0.1.0", | ||
"description": "A sane FTP client implementation for NodeJS", | ||
@@ -6,0 +6,0 @@ "keywords": [ "ftp", "streams", "files", "server", "client", "async" ], |
@@ -39,3 +39,3 @@ jsftp | ||
var user = "johndoe"; | ||
var pass = "12345" | ||
var pass = "12345"; | ||
@@ -80,3 +80,3 @@ var ftp = new Ftp({ | ||
// Create a directory | ||
ftp.raw.mkd("/example_dir", function(err, res) { | ||
ftp.raw.mkd("/example_dir", function(err, data) { | ||
if (err) | ||
@@ -89,3 +89,3 @@ throw err; | ||
// Delete a directory | ||
ftp.raw.rmd("/example_dir", function(err, res) { | ||
ftp.raw.rmd("/example_dir", function(err, data) { | ||
if (err) | ||
@@ -92,0 +92,0 @@ throw err; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
34
195164
3298