Explain Codes LogoExplain Codes Logo

How to download HTTP directory with all files and sub-directories as they appear on the online files/folders list?

html
wget
downloads
bookmarklets
Alex KataevbyAlex Kataev·Aug 16, 2024
TLDR

For swiftly pulling an entire HTTP directory, let wget save your day, well, bytes rather!

wget -r -np -N http://example.com/directory/
  • -r - getting down to the bottom level, where no file is ever too deep to reach.
  • -np - keeping the focus on the current path, no distractions from elsewhere.
  • -N - overwriting files only if remote ones are newer, because who enjoys old news?

Remember to replace http://example.com/directory/ with your own fancy URL.

Tweaking wget for personalized experience

Is wget gobbling up all the site data making you say "That's too much information!"? Then -l (depth) can restrict the depth of recursion. Couple that with -nH and --cut-dirs to tailor-make your local directory structure.

wget -r -np -l depth -nH --cut-dirs=3 -R "index.html*" http://example.com/directory/

Cool tip, -R can easily exclude files you would rather prefer to steer clear of.

Alternatives to wget: Pick your weapon!

Not fully satisfied with wget? No worries, VisualWGet offers a sleek GUI and lftp prides itself in handling complex jobs where wget might surrender.

lftp -e 'mirror --parallel=100; quit' http://example.com/directory/

Using --parallel turns you into a downloading wizard, handling 100 files all at once, because why wait?

Bookmarklets: Sniper targeting your downloads

If you want to download specific file types, bookmarklets or custom scripts can carve out a perfect path for you. Bookmarklets are nifty JavaScript pieces working their magic from your bookmarks bar.

javascript: (function () { var links = document.querySelectorAll("a[href$='.pdf']"); // Because who doesn't love hoarding PDFs links.forEach(function (link) { var href = link.getAttribute('href'); window.open(href, '_blank'); // Abracadabra! }); })();

With customized scripts, you're the artist and the web is your canvas. Exercise freedom and control over file extensions, pagination, and much more.

Error handling, advanced cases, and pro-tips

Be prepared for roadblocks such as network issues or even server tantrums. Yes, servers can get grumpy too! Alternate methods like cURL can help maneuver around these tight corners.

Documentation: Your treasure map!

Don't miss the manual pages and online documentation of these tools. They pack a punch with hidden gems and lay out the road to becoming a download ninja.