@@ -252,7 +252,7 @@ Client.prototype.upload = function(src, dest, callback) {
252
252
} ,
253
253
function ( stat , callback ) {
254
254
if ( stat . isDirectory ( ) ) return callback ( new Error ( 'Can not upload a directory' ) ) ;
255
-
255
+
256
256
// Get the attributes of the source directory
257
257
fs . stat ( path . dirname ( src ) , function ( err , dirStat ) {
258
258
if ( err ) return callback ( err ) ;
@@ -277,6 +277,9 @@ Client.prototype.upload = function(src, dest, callback) {
277
277
278
278
Client . prototype . download = function ( src , dest , callback ) {
279
279
var self = this ;
280
+ var transferInterval , transferIntervalId , lastBytes , totalBytes ;
281
+ transferInterval = this . options . transferInterval || 5000 ;
282
+ lastBytes = 0 ;
280
283
281
284
self . sftp ( function ( err , sftp ) {
282
285
if ( err ) {
@@ -287,12 +290,20 @@ Client.prototype.download = function(src, dest, callback) {
287
290
sftp_readStream . on ( 'error' , function ( err ) {
288
291
callback ( err ) ;
289
292
} ) ;
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 )
291
300
. on ( 'close' , function ( ) {
301
+ clearInterval ( transferIntervalId ) ;
292
302
self . emit ( 'read' , src ) ;
293
303
callback ( null ) ;
294
304
} )
295
305
. on ( 'error' , function ( err ) {
306
+ clearInterval ( transferIntervalId ) ;
296
307
callback ( err ) ;
297
308
} ) ;
298
309
} ) ;
0 commit comments