Comparing version 1.3.4 to 1.3.5
139
lib/jsftp.js
@@ -10,11 +10,13 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */ | ||
var Net = require("net"); | ||
var EventEmitter = require("events").EventEmitter; | ||
var es = require("event-stream"); | ||
var ResponseParser = require("ftp-response-parser"); | ||
var ListingParser = require("parse-listing"); | ||
var util = require("util"); | ||
var fs = require("fs"); | ||
var once = require("once"); | ||
'use strict'; | ||
var Net = require('net'); | ||
var EventEmitter = require('events').EventEmitter; | ||
var es = require('event-stream'); | ||
var ResponseParser = require('ftp-response-parser'); | ||
var ListingParser = require('parse-listing'); | ||
var util = require('util'); | ||
var fs = require('fs'); | ||
var once = require('once'); | ||
var FTP_PORT = 21; | ||
@@ -26,8 +28,8 @@ var TIMEOUT = 10 * 60 * 1000; | ||
// Commands without parameters | ||
"abor", "pwd", "cdup", "feat", "noop", "quit", "pasv", "syst", | ||
'abor', 'pwd', 'cdup', 'feat', 'noop', 'quit', 'pasv', 'syst', | ||
// Commands with one or more parameters | ||
"cwd", "dele", "list", "mdtm", "mkd", "mode", "nlst", "pass", "retr", "rmd", | ||
"rnfr", "rnto", "site", "stat", "stor", "type", "user", "xrmd", "opts", | ||
'cwd', 'dele', 'list', 'mdtm', 'mkd', 'mode', 'nlst', 'pass', 'retr', 'rmd', | ||
'rnfr', 'rnto', 'site', 'stat', 'stor', 'type', 'user', 'xrmd', 'opts', | ||
// Extended features | ||
"chmod", "size" | ||
'chmod', 'size' | ||
]; | ||
@@ -39,7 +41,7 @@ | ||
if (!match) { | ||
return cb(new Error("Bad passive host/port combination")); | ||
return cb(new Error('Bad passive host/port combination')); | ||
} | ||
cb(null, { | ||
host: match[1].replace(/,/g, "."), | ||
host: match[1].replace(/,/g, '.'), | ||
port: (parseInt(match[2], 10) & 255) * 256 + (parseInt(match[3], 10) & 255) | ||
@@ -54,6 +56,6 @@ }); | ||
if (args.length) { | ||
if (typeof args[args.length - 1] === "function") | ||
if (typeof args[args.length - 1] === 'function') | ||
callback = args.pop(); | ||
completeCmd += " " + args.join(" "); | ||
completeCmd += ' ' + args.join(' '); | ||
} | ||
@@ -64,3 +66,2 @@ this.execute(completeCmd.trim(), callback); | ||
var Ftp = module.exports = function(cfg) { | ||
"use strict"; | ||
@@ -85,5 +86,5 @@ Object.keys(cfg).forEach(function(opt) { | ||
// it is the responsability of the user to validate the parameters. | ||
this.raw = function() { | ||
this.raw = (function() { | ||
return runCmd.apply(this, arguments); | ||
}.bind(this); | ||
}).bind(this); | ||
COMMANDS.forEach(function(cmd) { | ||
@@ -124,4 +125,4 @@ this.raw[cmd] = runCmd.bind(this, cmd); | ||
var socket = Net.createConnection(port, host, firstAction || NOOP); | ||
socket.on("connect", this.reemit("connect")); | ||
socket.on("timeout", this.reemit("timeout")); | ||
socket.on('connect', this.reemit('connect')); | ||
socket.on('timeout', this.reemit('timeout')); | ||
@@ -141,3 +142,3 @@ this._createStreams(socket); | ||
}); | ||
this.pipeline.on("error", this.reemit("error")); | ||
this.pipeline.on('error', this.reemit('error')); | ||
}; | ||
@@ -174,10 +175,9 @@ | ||
* @param {String} command Command to write in the FTP socket | ||
* @return void | ||
*/ | ||
Ftp.prototype.send = function(command) { | ||
if (!command || typeof command !== "string") | ||
if (!command || typeof command !== 'string') | ||
return; | ||
this.emit("cmdSend", command); | ||
this.pipeline.write(command + "\r\n"); | ||
this.emit('cmdSend', command); | ||
this.pipeline.write(command + '\r\n'); | ||
@@ -208,3 +208,2 @@ if (this.debugMode) { | ||
* @param {function} callback | ||
* @return void | ||
*/ | ||
@@ -247,4 +246,4 @@ Ftp.prototype.execute = function(action, callback) { | ||
* | ||
* @param response {Object} Response from the server (contains text and code). | ||
* @param command {Array} Contains the command executed and a callback (if any). | ||
* @param {Object} response Response from the server (contains text and code). | ||
* @param {Array} command Contains the command executed and a callback (if any). | ||
*/ | ||
@@ -254,3 +253,3 @@ Ftp.prototype.parse = function(response, command) { | ||
if (response.isError) { | ||
err = new Error(response.text || "Unknown FTP error."); | ||
err = new Error(response.text || 'Unknown FTP error.'); | ||
err.code = response.code; | ||
@@ -268,3 +267,3 @@ } | ||
* @param {String} feature Feature to look for | ||
* @returns {Boolean} Whether the current server has the feature | ||
* @return {Boolean} Whether the current server has the feature | ||
*/ | ||
@@ -279,3 +278,3 @@ Ftp.prototype.hasFeat = function(feature) { | ||
* @param {String} features Server response for the 'FEAT' command | ||
* @returns {String[]} Array of feature names | ||
* @return {String[]} Array of feature names | ||
*/ | ||
@@ -307,5 +306,5 @@ Ftp.prototype._parseFeats = function(features) { | ||
* | ||
* @param user {String} Username | ||
* @param pass {String} Password | ||
* @param callback {Function} Follow-up function. | ||
* @param {String} user Username | ||
* @param {String} pass Password | ||
* @param {Function} callback Follow-up function. | ||
*/ | ||
@@ -325,4 +324,4 @@ Ftp.prototype.auth = function(user, pass, callback) { | ||
if (!user) user = "anonymous"; | ||
if (!pass) pass = "@anonymous"; | ||
if (!user) user = 'anonymous'; | ||
if (!pass) pass = '@anonymous'; | ||
@@ -341,7 +340,7 @@ this.authenticating = true; | ||
self.pass = pass; | ||
self.raw.type("I", function() { | ||
self.raw.type('I', function() { | ||
notifyAll(null, res); | ||
}); | ||
} else if (res.code === 332) { | ||
self.raw.acct(""); // ACCT not really supported | ||
self.raw.acct(''); // ACCT not really supported | ||
} | ||
@@ -377,3 +376,3 @@ }); | ||
callback = arguments[0]; | ||
path = ""; | ||
path = ''; | ||
} | ||
@@ -383,3 +382,3 @@ | ||
var cb = once(function(err, listing) { | ||
self.setType("I", once(function() { | ||
self.setType('I', once(function() { | ||
callback(err, listing); | ||
@@ -389,10 +388,10 @@ })); | ||
var listing = ""; | ||
this.setType("A", function() { | ||
var listing = ''; | ||
this.setType('A', function() { | ||
self.getPasvSocket(function(err, socket) { | ||
self.pasvTimeout.call(self, socket, cb); | ||
socket.on("data", function(data) { listing += data; }); | ||
socket.on("close", function(err) { cb(err, listing); }); | ||
socket.on("error", cb); | ||
socket.on('data', function(data) { listing += data; }); | ||
socket.on('close', function(err) { cb(err, listing); }); | ||
socket.on('error', cb); | ||
@@ -403,3 +402,3 @@ function cmdCallback(err, res) { | ||
if (res.code !== 125 && res.code !== 150) { | ||
cb(new Error("Unexpected command " + res.text)); | ||
cb(new Error('Unexpected command ' + res.text)); | ||
} | ||
@@ -413,3 +412,3 @@ } | ||
self.execute("list " + (path || ""), cmdCallback); | ||
self.execute('list ' + (path || ''), cmdCallback); | ||
}); | ||
@@ -437,3 +436,3 @@ }); | ||
* @param {String} localPath Local path where the new file will be created | ||
* @param {Function} [callback] Gets called on either success or failure | ||
* @param {Function} callback Gets called on either success or failure | ||
*/ | ||
@@ -452,2 +451,7 @@ Ftp.prototype.get = function(remotePath, localPath, callback) { | ||
if (!socket) { | ||
return callback(new Error('An unknown error occurred when trying to ' + | ||
'retrieve the passive socket')); | ||
} | ||
var writeStream = fs.createWriteStream(localPath); | ||
@@ -475,4 +479,5 @@ writeStream.on('error', callback); | ||
* | ||
* @param path {String} Path to the file to be retrieved | ||
* @param callback {Function} Function to call when finalized, with the socket as a parameter | ||
* @param {String} path Path to the file to be retrieved | ||
* @param {Function} callback Function to call when finalized, with the socket | ||
* as a parameter | ||
*/ | ||
@@ -494,3 +499,3 @@ Ftp.prototype.getGetSocket = function(path, callback) { | ||
else | ||
callback(new Error("Unexpected command " + res.text)); | ||
callback(new Error('Unexpected command ' + res.text)); | ||
} | ||
@@ -502,3 +507,3 @@ | ||
}; | ||
self.execute("retr " + path, cmdCallback); | ||
self.execute('retr ' + path, cmdCallback); | ||
}); | ||
@@ -519,6 +524,6 @@ }; | ||
function putReadable(from, to, totalSize, callback) { | ||
from.on("readable", function() { | ||
from.on('readable', function() { | ||
self.emitProgress({ | ||
filename: to, | ||
action: "put", | ||
action: 'put', | ||
socket: from, | ||
@@ -539,6 +544,6 @@ totalSize: totalSize | ||
}, callback); | ||
} else if (typeof from === "string" || from instanceof String) { | ||
} else if (typeof from === 'string' || from instanceof String) { | ||
fs.exists(from, function(exists) { | ||
if (!exists) | ||
return callback(new Error("Local file doesn't exist.")); | ||
return callback(new Error('Local file doesn\'t exist.')); | ||
@@ -559,3 +564,3 @@ fs.stat(from, function(err, stats) { | ||
Ftp.prototype.getPutSocket = function(path, callback, doneCallback) { | ||
if (!callback) throw new Error("A callback argument is required."); | ||
if (!callback) throw new Error('A callback argument is required.'); | ||
@@ -586,3 +591,3 @@ doneCallback = once(doneCallback || NOOP); | ||
} else { | ||
return _callback(new Error("Unexpected command " + res.text)); | ||
return _callback(new Error('Unexpected command ' + res.text)); | ||
} | ||
@@ -594,3 +599,3 @@ }); | ||
}; | ||
self.execute("stor " + path, putCallback); | ||
self.execute('stor ' + path, putCallback); | ||
}); | ||
@@ -604,3 +609,3 @@ }; | ||
socket.destroy(); | ||
cb(new Error("Passive socket timeout")); | ||
cb(new Error('Passive socket timeout')); | ||
}); | ||
@@ -612,3 +617,3 @@ }; | ||
callback = once(callback || NOOP); | ||
this.execute("pasv", function(err, res) { | ||
this.execute('pasv', function(err, res) { | ||
if (err) return callback(err); | ||
@@ -649,4 +654,4 @@ | ||
* | ||
* @param filePath {String} Path to the file or directory to list | ||
* @param callback {Function} Function to call with the proper data when | ||
* @param {String} filePath Path to the file or directory to list | ||
* @param {Function} callback Function to call with the proper data when | ||
* the listing is finished. | ||
@@ -673,4 +678,4 @@ */ | ||
if ((err && (err.code === 502 || err.code === 500)) || | ||
(self.system && self.system.indexOf("hummingbird") > -1)) | ||
// Not sure if the "hummingbird" system check ^^^ is still | ||
(self.system && self.system.indexOf('hummingbird') > -1)) | ||
// Not sure if the 'hummingbird' system check ^^^ is still | ||
// necessary. If they support any standards, the 500 error | ||
@@ -690,3 +695,3 @@ // should have us covered. Let's leave it for now. | ||
var self = this; | ||
this.raw.rnfr(from, function(err, res) { | ||
this.raw.rnfr(from, function(err) { | ||
if (err) return callback(err); | ||
@@ -693,0 +698,0 @@ self.raw.rnto(to, function(err, res) { |
{ | ||
"name": "jsftp", | ||
"id": "jsftp", | ||
"version": "1.3.4", | ||
"version": "1.3.5", | ||
"description": "A sane FTP client implementation for NodeJS", | ||
@@ -19,3 +19,3 @@ "keywords": [ "ftp", "protocol", "files", "server", "client", "async" ], | ||
"ftp-response-parser": "1.0.0", | ||
"parse-listing": "1.1.0", | ||
"parse-listing": "1.1.1", | ||
"once": "1.3.0" | ||
@@ -22,0 +22,0 @@ }, |
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
1301
57037
15
+ Addedparse-listing@1.1.1(transitive)
- Removedasync@0.2.10(transitive)
- Removedparse-listing@1.1.0(transitive)
Updatedparse-listing@1.1.1