Permalink
Browse files

v0.2.8

  • Loading branch information...
1 parent 7dc2cd5 commit 66807e524ee447c57780d4e792bf8efa55239a37 @SaltwaterC committed Jan 25, 2012
Showing with 37 additions and 4 deletions.
  1. +4 −0 CHANGELOG.md
  2. +32 −3 lib/ftp-get.js
  3. +1 −1 package.json
View
@@ -1,3 +1,7 @@
+## v0.2.8
+ * Fixes the ftp.head() not calling the callback when the underlying socket closes prematurely. Uses the same patch for ftp.get() in order to fail faster than waiting for the data socket to timeout.
+ * The close / error events for both ftp.get() and ftp.head() both call the callback with the same set of properties.
+
## v0.2.7
* Fixes the ftp.head() for when socket errors are emitted.
View
@@ -52,7 +52,7 @@ exports.get = function (url, file, cb) {
url = processUrl(url);
var cmdSock = dataSock = null;
- var ftpErr = false;
+ var ftpErr = ended = false;
if ( ! file) {
var buf = '';
@@ -101,6 +101,7 @@ exports.get = function (url, file, cb) {
var cleanupGarbage = function () {
ftpErr = true;
+ ended = true;
if (pasvTimeout) {
clearTimeout(pasvTimeout);
}
@@ -215,6 +216,7 @@ exports.get = function (url, file, cb) {
dataSock.on('end', function () {
if ( ! ftpErr) {
+ ended = true;
cmdSock.end();
if ( ! file) {
cb(null, buf);
@@ -260,11 +262,21 @@ exports.get = function (url, file, cb) {
cb(err);
}
});
+
+ cmdSock.on('close', function () {
+ if ( ! ended) {
+ cleanupGarbage();
+ var err = new Error('The command socket closed prematurely.');
+ err.code = 5; // command socket failure
+ err.url = url;
+ cb(err);
+ }
+ });
};
exports.head = function (url, cb) {
url = processUrl(url);
- var ftpErr = false;
+ var ftpErr = ended = false;
var cmdSock = net.createConnection(url.port, url.hostname);
cmdSock.setEncoding('utf8');
@@ -297,6 +309,7 @@ exports.head = function (url, cb) {
var cleanupGarbage = function () {
ftpErr = true;
+ ended = true;
if (cmdSock) {
cmdSock.destroy();
}
@@ -318,6 +331,7 @@ exports.head = function (url, cb) {
errorWatch(data);
cmdWrite('SIZE ' + url.pathname, function (data) {
errorWatch(data);
+ ended = true;
cmdSock.end();
if ( ! ftpErr) {
cb(null, data.substr(4, data.length - 6));
@@ -330,6 +344,21 @@ exports.head = function (url, cb) {
});
cmdSock.on('error', function (err) {
- cb(err);
+ if ( ! ftpErr) {
+ cleanupGarbage();
+ err.code = 5; // command socket failure
+ err.url = url;
+ cb(err);
+ }
+ });
+
+ cmdSock.on('close', function () {
+ if ( ! ended) {
+ cleanupGarbage();
+ var err = new Error('The command socket closed prematurely.');
+ err.code = 5; // command socket failure
+ err.url = url;
+ cb(err);
+ }
});
};
View
@@ -1,6 +1,6 @@
{
"name": "ftp-get",
- "version": "0.2.7",
+ "version": "0.2.8",
"main": "./lib/ftp-get.js",
"description": "Simple to use node.js FTP client for downloading remote files",
"engines": {

0 comments on commit 66807e5

Please sign in to comment.