@@ -252,7 +252,7 @@ Client.prototype.upload = function(src, dest, callback) {
252252 } ,
253253 function ( stat , callback ) {
254254 if ( stat . isDirectory ( ) ) return callback ( new Error ( 'Can not upload a directory' ) ) ;
255-
255+
256256 // Get the attributes of the source directory
257257 fs . stat ( path . dirname ( src ) , function ( err , dirStat ) {
258258 if ( err ) return callback ( err ) ;
@@ -277,6 +277,9 @@ Client.prototype.upload = function(src, dest, callback) {
277277
278278Client . prototype . download = function ( src , dest , callback ) {
279279 var self = this ;
280+ var transferInterval , transferIntervalId , lastBytes , totalBytes ;
281+ transferInterval = this . _options . transferInterval || 5000 ;
282+ lastBytes = 0 ;
280283
281284 self . sftp ( function ( err , sftp ) {
282285 if ( err ) {
@@ -287,12 +290,20 @@ Client.prototype.download = function(src, dest, callback) {
287290 sftp_readStream . on ( 'error' , function ( err ) {
288291 callback ( err ) ;
289292 } ) ;
290- sftp_readStream . pipe ( fs . createWriteStream ( dest ) )
293+ fsDest = fs . createWriteStream ( dest ) ;
294+ transferIntervalId = setInterval ( function ( ) {
295+ totalBytes = fsDest . bytesWritten ;
296+ lastBytes = totalBytes - lastBytes ;
297+ self . emit ( 'transfer' , fsDest , lastBytes , totalBytes ) ;
298+ } , transferInterval ) ;
299+ sftp_readStream . pipe ( fsDest )
291300 . on ( 'close' , function ( ) {
301+ clearInterval ( transferIntervalId ) ;
292302 self . emit ( 'read' , src ) ;
293303 callback ( null ) ;
294304 } )
295305 . on ( 'error' , function ( err ) {
306+ clearInterval ( transferIntervalId ) ;
296307 callback ( err ) ;
297308 } ) ;
298309 } ) ;
0 commit comments