lib/helpers/child-process.js
function downloadFile(cb) {
      if(task.file_path) {
        // Download the file
        var stream = fs.createWriteStream(path);

        // Store error if statusCode !== 200
        var err;
        stream.on("finish", function() {
          cb(err);
        });

        var urlToDownload = url.parse(task.file_path, false, true);

        // deny queries to ElasticSearch and other vulnerable services
        if(task.config.forbiddenPorts && task.config.forbiddenPorts.indexOf(urlToDownload.port) !== -1) {
          stream.end();
          return fs.unlink(path, function() {
            cb(new Error('Trying to access forbidden port: ' + urlToDownload.port));
          });
        }

        var req = request(urlToDownload.protocol + "//" + urlToDownload.host)
          .get(urlToDownload.path);

        // Warning, Black magic.
        // Streaming and checking for status code is no easy task...
        // Hours spent optimizing: 22
        req.end(function() {}).req.once('response', function(res) {
          if(res.statusCode !== 200) {
            if(res.statusCode === 410) {
              err = new Error('410 Gone');
              err.skip = true;
            }
            else {
              err = new Error('Error downloading file, got status ' + res.statusCode);
            }

            stream.end();
            this.abort();
          }
        });
        req.pipe(stream);
      }
      else {
        cb(null);
      }
    }
function downloadFile(cb) {
      if(task.file_path) {
        // Download the file
        var stream = fs.createWriteStream(path);

        // Store error if statusCode !== 200
        var err;
        stream.on("finish", function() {
          cb(err);
        });

        var urlToDownload = url.parse(task.file_path, false, true);

        // deny queries to ElasticSearch and other vulnerable services
        if(task.config.forbiddenPorts && task.config.forbiddenPorts.indexOf(urlToDownload.port) !== -1) {
          stream.end();
          return fs.unlink(path, function() {
            cb(new Error('Trying to access forbidden port: ' + urlToDownload.port));
          });
        }

        var req = request(urlToDownload.protocol + "//" + urlToDownload.host)
          .get(urlToDownload.path);

        // Warning, Black magic.
        // Streaming and checking for status code is no easy task...
        // Hours spent optimizing: 22
        req.end(function() {}).req.once('response', function(res) {
          if(res.statusCode !== 200) {
            if(res.statusCode === 410) {
              err = new Error('410 Gone');
              err.skip = true;
            }
            else {
              err = new Error('Error downloading file, got status ' + res.statusCode);
            }

            stream.end();
            this.abort();
          }
        });
        req.pipe(stream);
      }
      else {
        cb(null);
      }
    }
function downloadFile ( cb ) { if ( task . file_path ) { // Download the file var stream = fs . createWriteStream ( path ) ; // Store error if statusCode !== 200 var err ; stream . on ( "finish" , function ( ) { cb ( err ) ; } ) ; var urlToDownload = url . parse ( task . file_path , false , true ) ; // deny queries to ElasticSearch and other vulnerable services if ( task . config . forbiddenPorts && task . config . forbiddenPorts . indexOf ( urlToDownload . port ) !== - 1 ) { stream . end ( ) ; return fs . unlink ( path , function ( ) { cb ( new Error ( 'Trying to access forbidden port: ' + urlToDownload . port ) ) ; } ) ; } var req = request ( urlToDownload . protocol + "//" + urlToDownload . host ) . get ( urlToDownload . path ) ; // Warning, Black magic. // Streaming and checking for status code is no easy task... // Hours spent optimizing: 22 req . end ( function ( ) { } ) . req . once ( 'response' , function ( res ) { if ( res . statusCode !== 200 ) { if ( res . statusCode === 410 ) { err = new Error ( '410 Gone' ) ; err . skip = true ; } else { err = new Error ( 'Error downloading file, got status ' + res . statusCode ) ; } stream . end ( ) ; this . abort ( ) ; } } ) ; req . pipe ( stream ) ; } else { cb ( null ) ; } }
Download the file from task.file_path, store it in a temporary file if there is file_path
Download the file from task . file_path store it in a temporary file if there is file_path