@@ -107,7 +107,7 @@ Ftp.prototype.reemit = function(event) {
107107 if ( self . debugMode ) {
108108 self . emit ( 'jsftp_debug' , 'event:' + event , data || { } ) ;
109109 }
110- }
110+ } ;
111111} ;
112112
113113Ftp . prototype . _createSocket = function ( port , host , firstAction ) {
@@ -143,12 +143,10 @@ Ftp.prototype.parseResponse = function(data) {
143143
144144 var next = this . cmdBuffer_ [ 0 ] [ 1 ] ;
145145 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
148147 if ( ! next . expectsMark || next . expectsMark . marks . indexOf ( data . code ) === - 1 )
149148 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.
152150 if ( next . expectsMark . ignore )
153151 this . ignoreCmdCode = next . expectsMark . ignore ;
154152 }
@@ -353,7 +351,7 @@ Ftp.prototype.setType = function(type, callback) {
353351/**
354352 * Lists a folder's contents using a passive connection.
355353 *
356- * @param {String } [ path] Remote path for the file/folder to retrieve
354+ * @param {String } path Remote path for the file/folder to retrieve
357355 * @param {Function } callback Function to call with errors or results
358356 */
359357Ftp . prototype . list = function ( path , callback ) {
@@ -363,30 +361,35 @@ Ftp.prototype.list = function(path, callback) {
363361 }
364362
365363 var self = this ;
366- var cb = function ( err , listing ) {
364+ var cb = once ( function ( err , listing ) {
367365 self . setType ( "I" , once ( function ( ) {
368366 callback ( err , listing ) ;
369367 } ) ) ;
370- } ;
371- cb . expectsMark = {
372- marks : [ 125 , 150 ] ,
373- ignore : 226
374- } ;
368+ } ) ;
375369
376370 var listing = "" ;
377371 this . setType ( "A" , function ( ) {
378372 self . getPasvSocket ( function ( err , socket ) {
379- self . pasvTimeout . bind ( self , socket , cb ) ;
373+ self . pasvTimeout . call ( self , socket , cb ) ;
380374
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 ) ; } ) ;
387377 socket . on ( "error" , cb ) ;
388378
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 ) ;
390393 } ) ;
391394 } ) ;
392395} ;
@@ -454,7 +457,7 @@ Ftp.prototype.getGetSocket = function(path, callback) {
454457 this . getPasvSocket ( function ( err , socket ) {
455458 if ( err ) return cmdCallback ( err ) ;
456459
457- self . pasvTimeout . bind ( self , socket , cmdCallback ) ;
460+ self . pasvTimeout . call ( self , socket , cmdCallback ) ;
458461 socket . pause ( ) ;
459462
460463 function cmdCallback ( err , res ) {
@@ -547,7 +550,7 @@ Ftp.prototype.getPutSocket = function(path, callback, doneCallback) {
547550 if ( res . code === 125 || res . code === 150 ) {
548551 socket . on ( 'close' , doneCallback ) ;
549552 socket . on ( 'error' , doneCallback ) ;
550- self . pasvTimeout . bind ( self , socket , doneCallback ) ;
553+ self . pasvTimeout . call ( self , socket , doneCallback ) ;
551554 _callback ( null , socket ) ;
552555 } else {
553556 return _callback ( new Error ( "Unexpected command " + res . text ) ) ;
0 commit comments