--- /dev/null
+#!/usr/bin/perl
+# dropbox_recursive recursively downloads files from dropbox
+# and is released under the terms of the GNU GPL version 3, or any
+# later version, at your option. See the file README and COPYING for
+# more information.
+# Copyright 2014 by Don Armstrong <don@donarmstrong.com>.
+
+
+use warnings;
+use strict;
+
+use Getopt::Long;
+use Pod::Usage;
+
+=head1 NAME
+
+dropbox_recursive - recursively downloads files from dropbox
+
+=head1 SYNOPSIS
+
+dropbox_recursive [options] dropboxurl1 [additional dropbox urls]
+
+ Options:
+ --debug, -d debugging level (Default 0)
+ --help, -h display this help
+ --man, -m display manual
+
+=head1 OPTIONS
+
+=over
+
+=item B<--debug, -d>
+
+Debug verbosity. (Default 0)
+
+=item B<--help, -h>
+
+Display brief usage information.
+
+=item B<--man, -m>
+
+Display this manual.
+
+=back
+
+=head1 EXAMPLES
+
+dropbox_recursive https://www.dropbox.com/sh/foo/bar
+
+=cut
+
+
+use vars qw($DEBUG);
+
+my %options = (debug => 0,
+ help => 0,
+ man => 0,
+ );
+
+GetOptions(\%options,
+ 'debug|d+','help|h|?','man|m');
+
+pod2usage() if $options{help};
+pod2usage({verbose=>2}) if $options{man};
+
+$DEBUG = $options{debug};
+
+use URI::Escape;
+use WWW::Mechanize;
+
+my @USAGE_ERRORS;
+if (not @ARGV) {
+ push @USAGE_ERRORS,"You must give at least one dropbox url";
+}
+
+pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
+
+
+
+my $mech = WWW::Mechanize->new();
+for my $url (@ARGV) {
+ $mech->get($url);
+ download_url($mech);
+}
+
+sub download_url {
+ my ($m) = @_;
+
+
+ my @links = $m->find_all_links(class=>"filename-link");
+ print STDERR map {$_->url()."\n"} @links;
+ for my $link (@links) {
+ $m->get($link->url());
+ my ($name) = $m->uri() =~ m{/([^/]+)$};
+ $name = uri_unescape($name);
+ # see if there is a download button
+ my @download_button = $m->find_all_links(id=>'default_content_download_button');
+ # If there's a download button, then we've visted the link for a
+ # file; save it.
+ if (@download_button) {
+ print STDERR "getting file $name\n";
+ $m->get($download_button[0]->url(),':content_file'=>$name);
+ print STDERR "got file $name\n";
+ } else {
+ # there isn't a download button, so we must have visited
+ # the link for a directory
+ mkdir $name unless -d $name;
+ print STDERR "made directory $name\n";
+ chdir $name or die "Unable to chdir to $name";
+ download_url($m);
+ chdir '..';
+ }
+ }
+}
+
+
+__END__