tags/webbloghttp://blog.spang.cc/tags/web/blogikiwiki2010-07-12T18:16:04Zdownloading a directory via HTTP with wgethttp://blog.spang.cc/posts/downloading_a_directory_via_HTTP_with_wget/2010-07-12T18:16:04Z2010-07-12T18:13:00Z
<p>From the department of
things-that-I-know-are-possible-but-can-never-remember-how-to-do-so-hey-I-read-the-manpage-and-now-I'm-blogging-it,
I bring you "downloading a directory of photos from a website":</p>
<pre><code> wget --recursive http://example.com/photos/some-event/ --no-directories --directory-prefix <local-folder-name> --accept JPG,RW2
</code></pre>
<p>I always remember <code>wget --recursive</code> (or <code>wget -r</code>
for short), but that produces an annoying tree of directories starting
with the website's domain and working its way up to the directory you
actually want. In the command above, <code>--no-directories</code>
removes the tree, and <code>--directory-prefix</code> tells
<code>wget</code> to put the downloaded files somewhere that's not the
current working directory. The <code>--accept</code> option tells
<code>wget</code> to discard files with extensions other than those
mentioned, so your downloaded directory is not cluttered with
webserver-generated files like <code>index.html</code> if you don't want
it to be.</p>
<p>Here's the short version, since the long version is nice to remember but
not so nice to type:</p>
<pre><code>wget -r http://example.com/photos/some-event/ -nd -P <local-folder-name> -A JPG,RW2
</code></pre>