@@ -107,7 +107,7 @@ Ftp.prototype.reemit = function(event) {
107
107
if ( self . debugMode ) {
108
108
self . emit ( 'jsftp_debug' , 'event:' + event , data || { } ) ;
109
109
}
110
- }
110
+ } ;
111
111
} ;
112
112
113
113
Ftp . prototype . _createSocket = function ( port , host , firstAction ) {
@@ -143,12 +143,10 @@ Ftp.prototype.parseResponse = function(data) {
143
143
144
144
var next = this . cmdBuffer_ [ 0 ] [ 1 ] ;
145
145
if ( data . isMark ) {
146
- // If we receive a Mark and it is not expected, we ignore
147
- // that command
146
+ // If we receive a Mark and it is not expected, we ignore that command
148
147
if ( ! next . expectsMark || next . expectsMark . marks . indexOf ( data . code ) === - 1 )
149
148
return ;
150
- // We might have to ignore the command that comes after the
151
- // mark.
149
+ // We might have to ignore the command that comes after the mark.
152
150
if ( next . expectsMark . ignore )
153
151
this . ignoreCmdCode = next . expectsMark . ignore ;
154
152
}
@@ -353,7 +351,7 @@ Ftp.prototype.setType = function(type, callback) {
353
351
/**
354
352
* Lists a folder's contents using a passive connection.
355
353
*
356
- * @param {String } [ path] Remote path for the file/folder to retrieve
354
+ * @param {String } path Remote path for the file/folder to retrieve
357
355
* @param {Function } callback Function to call with errors or results
358
356
*/
359
357
Ftp . prototype . list = function ( path , callback ) {
@@ -363,30 +361,35 @@ Ftp.prototype.list = function(path, callback) {
363
361
}
364
362
365
363
var self = this ;
366
- var cb = function ( err , listing ) {
364
+ var cb = once ( function ( err , listing ) {
367
365
self . setType ( "I" , once ( function ( ) {
368
366
callback ( err , listing ) ;
369
367
} ) ) ;
370
- } ;
371
- cb . expectsMark = {
372
- marks : [ 125 , 150 ] ,
373
- ignore : 226
374
- } ;
368
+ } ) ;
375
369
376
370
var listing = "" ;
377
371
this . setType ( "A" , function ( ) {
378
372
self . getPasvSocket ( function ( err , socket ) {
379
- self . pasvTimeout . bind ( self , socket , cb ) ;
373
+ self . pasvTimeout . call ( self , socket , cb ) ;
380
374
381
- socket . on ( "data" , function ( data ) {
382
- listing += data ;
383
- } ) ;
384
- socket . on ( "close" , function ( err ) {
385
- cb ( err || null , listing ) ;
386
- } ) ;
375
+ socket . on ( "data" , function ( data ) { listing += data ; } ) ;
376
+ socket . on ( "close" , function ( err ) { cb ( err , listing ) ; } ) ;
387
377
socket . on ( "error" , cb ) ;
388
378
389
- self . send ( "list " + ( path || "" ) ) ;
379
+ function cmdCallback ( err , res ) {
380
+ if ( err ) return cb ( err ) ;
381
+
382
+ if ( res . code !== 125 && res . code !== 150 ) {
383
+ cb ( new Error ( "Unexpected command " + res . text ) ) ;
384
+ }
385
+ }
386
+
387
+ cmdCallback . expectsMark = {
388
+ marks : [ 125 , 150 ] ,
389
+ ignore : 226
390
+ } ;
391
+
392
+ self . execute ( "list " + ( path || "" ) , cmdCallback ) ;
390
393
} ) ;
391
394
} ) ;
392
395
} ;
@@ -454,7 +457,7 @@ Ftp.prototype.getGetSocket = function(path, callback) {
454
457
this . getPasvSocket ( function ( err , socket ) {
455
458
if ( err ) return cmdCallback ( err ) ;
456
459
457
- self . pasvTimeout . bind ( self , socket , cmdCallback ) ;
460
+ self . pasvTimeout . call ( self , socket , cmdCallback ) ;
458
461
socket . pause ( ) ;
459
462
460
463
function cmdCallback ( err , res ) {
@@ -547,7 +550,7 @@ Ftp.prototype.getPutSocket = function(path, callback, doneCallback) {
547
550
if ( res . code === 125 || res . code === 150 ) {
548
551
socket . on ( 'close' , doneCallback ) ;
549
552
socket . on ( 'error' , doneCallback ) ;
550
- self . pasvTimeout . bind ( self , socket , doneCallback ) ;
553
+ self . pasvTimeout . call ( self , socket , doneCallback ) ;
551
554
_callback ( null , socket ) ;
552
555
} else {
553
556
return _callback ( new Error ( "Unexpected command " + res . text ) ) ;
0 commit comments