Dropbox makes it easy to programmatically download a single file via curl (EX: curl -O https://dl.dropboxusercontent.com/s/file.ext
). It is a little bit trickier for a folder (regular directory folder, not zipped). The shared link for a folder, as opposed to a file, does not link directly to the zipped folder (Dropbox automatically zips the folder before it is downloaded). It would appear that you could just add ?dl=1
to the end of the link, as this will directly start the download in a browser. This, however, points to an intermediary html document that redirects to the actual zip folder and does not seem to work with curl. Is there anyway to use curl to download a folder via a shared link? I realize that the best solution would be to use the Dropbox api, but for this project it is important to keep it as simple as possible. Additionally, the solution must be incorporated into a bash shell script.
You can send a shared link by email, Facebook, Twitter, instant message, social networks, wherever you want. Shared links are view-only, and by default anyone with the link can view and download its contents. Dropbox Professional and Dropbox Business customers can add passwords and expirations to shared links.
Go to Dropbox.com, find your file, and click the Copy link button that appears when you hover over it. Or, on your desktop, right-click on the file, and select Copy Dropbox Link. Copy that link and paste it in your browser, and it should download the file directly.
Hover over the name of the file or folder and click the share icon (rectangle with an up arrow). Click Settings. Click either Link for editing or Link for viewing depending on which link you'd like to disable downloads for. Next to Disable downloads, click to toggle it On.
It does appear to be possible with curl by using the -L
option. This forces curl to follow the redirect. Additionally, it is important to specify an output name with a .zip extension, as the default will be a random alpha-numeric name with no extension. Finally, do not forget to add the ?dl=1
to the end of the link. Without it, curl will never reach the redirect page.
curl -L -o newName.zip https://www.dropbox.com/sh/[folderLink]?dl=1
Follow redirects (use -L
). Your immediate problem is that Curl is not following redirects.
Set a filename. (Optional)
Use one of these commands:
curl https://www.dropbox.com/sh/AAbbCCEeFF123?dl=1 -O -J -L
Preserve/write the remote filename (-O
,-J
) and follows any redirects (-L
).
.zip
automatically (based on folder name).?dl=0
to ?dl=1
(see comments).OR:
curl https://www.dropbox.com/sh/AAbbCCEeFF123?dl=1 -L -o [filename]
Follow any redirects (-L
) and set a filename (-o
) of your choosing.
NOTE: Using the -J
flag in general:
WARNING: Exercise judicious use of this option, especially on Windows. A rogue server could send you the name of a DLL or other file that could possibly be loaded automatically by Windows or some third party software.
Please consult: https://curl.haxx.se/docs/manpage.html#OPTIONS (See: -O, -J, -L, -o) for more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With