Skip to content

Commit

Permalink
Get rid of string decoder when downloading/uploading files and fix li…
Browse files Browse the repository at this point in the history
…st() to check for only boolean and callback
  • Loading branch information
mscdex committed Aug 29, 2012
1 parent b3b10f9 commit 60c7f02
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions ftp.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ FTP.prototype.get = function(path, cb) {
if (e)
return cb(e);

stream._decoder = undefined;
var r = self.send('RETR', path, function(e) {
if (e)
return stream.emit('error', e);
Expand All @@ -297,6 +298,7 @@ FTP.prototype.put = function(instream, destpath, cb) {
if (e)
return cb(e);

stream._decoder = undefined;

This comment has been minimized.

Copy link
@vlizard

vlizard Sep 6, 2012

I've got this trying to upload file:
ReferenceError: stream is not defined

This comment has been minimized.

Copy link
@mscdex

mscdex Sep 6, 2012

Author Owner

@vlizard fixed in v0.1.5

var r = self.send('STOR', destpath, cb);
if (r) {
instream.pipe(outstream);
Expand Down Expand Up @@ -379,6 +381,10 @@ FTP.prototype.list = function(path, streaming, cb) {
cb = path;
path = undefined;
streaming = false;
} else if (typeof path === 'boolean') {
cb = streaming;
streaming = path;
path = undefined;
}
if (typeof streaming === 'function') {
cb = streaming;
Expand Down Expand Up @@ -521,43 +527,39 @@ FTP.prototype._pasvConnect = function() {

var self = this;

this._pasvTimeout = setTimeout(function() {
var r = self.send('ABOR', function(e) {
self._dataSock.end();
self._pasvPort = self._pasvIP = undefined;
if (e)
return self._callCb(e);
self._callCb(new Error('(PASV) Data connection timed out while connecting'));
});
if (!r)
self._callCb(new Error('Connection severed'));
}, this.options.connTimeout);

this.debug&&this.debug('(PASV) About to attempt data connection to: '
+ this._pasvIP + ':' + this._pasvPort);

if (!this._dataSock) {
this._dataSock = new net.Socket();
this._dataSock.on('connect', function() {
clearTimeout(self._pasvTimeout);
var s = this._dataSock = new net.Socket();
s.on('connect', function() {
clearTimeout(s._pasvTimeout);
self.debug&&self.debug('(PASV) Data connection successful');
self._callCb(self._dataSock);
self._callCb(s);
});
this._dataSock.on('end', function() {
s.on('end', function() {
self.debug&&self.debug('(PASV) Data connection closed');
self._pasvPort = self._pasvIP = undefined;
});
this._dataSock.on('close', function() {
s.on('close', function(had_err) {
clearTimeout(self._pasvTimeout);
self._pasvPort = self._pasvIP = undefined;
self._dataSock = undefined;
});
this._dataSock.on('error', function(err) {
s.on('error', function(err) {
self.debug&&self.debug('(PASV) Error: ' + err);
self._pasvPort = self._pasvIP = undefined
self._callCb(err);
});
}

this._dataSock.connect(this._pasvPort, this._pasvIP);
s._pasvTimeout = setTimeout(function() {
var r = self.send('ABOR', function(e) {
s.destroy();
if (e)
return self._callCb(e);
self._callCb(new Error('(PASV) Data connection timed out while connecting'));
});
if (!r)
self._callCb(new Error('Connection severed'));
}, this.options.connTimeout);

s.connect(this._pasvPort, this._pasvIP);

return true;
};
Expand Down

0 comments on commit 60c7f02

Please sign in to comment.