tasks/ftp_push.js
function uploadFiles(files) {
    var index = 0,
        file = files[index];

    /**
    * Recursive helper used as callback for server.raw(put)
    * @param {error} err - Error message if something went wrong
    */
    var processFile = function processFile (err) {
      if (err) {
        grunt.log.warn(messages.fileTransferFail(file.dest, err));
      } else {
        grunt.log.ok(messages.fileTransferSuccess(file.dest));
      }

      ++index;
      // If there are more files, then keep pushing
      if (index < files.length) {
        file = files[index];
        server.put(grunt.file.read(file.src, { encoding: null }), file.dest, processFile);
      } else {
        // Close the connection, we are complete
        server.raw('quit', function(quitErr) {
          if (quitErr) {
            grunt.log.error(quitErr);
            done(false);
          }
          server.destroy();
          grunt.log.ok(messages.connectionClosed);
          done();
        });
      }
    };

    // Start uploading files
    server.put(grunt.file.read(file.src, { encoding: null }), file.dest, processFile);
  }
function uploadFiles(files) {
    var index = 0,
        file = files[index];

    /**
    * Recursive helper used as callback for server.raw(put)
    * @param {error} err - Error message if something went wrong
    */
    var processFile = function processFile (err) {
      if (err) {
        grunt.log.warn(messages.fileTransferFail(file.dest, err));
      } else {
        grunt.log.ok(messages.fileTransferSuccess(file.dest));
      }

      ++index;
      // If there are more files, then keep pushing
      if (index < files.length) {
        file = files[index];
        server.put(grunt.file.read(file.src, { encoding: null }), file.dest, processFile);
      } else {
        // Close the connection, we are complete
        server.raw('quit', function(quitErr) {
          if (quitErr) {
            grunt.log.error(quitErr);
            done(false);
          }
          server.destroy();
          grunt.log.ok(messages.connectionClosed);
          done();
        });
      }
    };

    // Start uploading files
    server.put(grunt.file.read(file.src, { encoding: null }), file.dest, processFile);
  }
function uploadFiles ( files ) { var index = 0 , file = files [ index ] ; /**
    * Recursive helper used as callback for server.raw(put)
    * @param {error} err - Error message if something went wrong
    */ var processFile = function processFile ( err ) { if ( err ) { grunt . log . warn ( messages . fileTransferFail ( file . dest , err ) ) ; } else { grunt . log . ok ( messages . fileTransferSuccess ( file . dest ) ) ; } ++ index ; // If there are more files, then keep pushing if ( index < files . length ) { file = files [ index ] ; server . put ( grunt . file . read ( file . src , { encoding : null } ) , file . dest , processFile ) ; } else { // Close the connection, we are complete server . raw ( 'quit' , function ( quitErr ) { if ( quitErr ) { grunt . log . error ( quitErr ) ; done ( false ) ; } server . destroy ( ) ; grunt . log . ok ( messages . connectionClosed ) ; done ( ) ; } ) ; } } ; // Start uploading files server . put ( grunt . file . read ( file . src , { encoding : null } ) , file . dest , processFile ) ; }
Helper function that uses a recursive style for uploading files until none remain
@param {object[]} files - Array of file objects to upload, {src: '...', dest: '...'}
Helper function that uses a recursive style for uploading files until none remain