how to download dropbox files using wget command?

73

24

Seems I can only download dropbox files using explorer such as chrome and firefox. If I use wget to download, then I would get a file which is in html format. Why?

For example you can open this link

You would not get the content of this file, why? The following is part of test.txt to download it, this is not the content of test.txt at all.

So is it possible to download Dropbox files using wget rather than explorer?

document.observe('script:loaded', function() {
SharingModel.init('test\x2etxt', Util.from_json('\x7b\x22item\x5fid\x22\x3a\x20\x22\x22\x2c\x20\x22secure\x5fhash\x22\x3a\x20\x22\x22\x2c\x20\x22subpath\x22\x3a\x20\x22\x22\x2c\x20\x22tkey\x22\x3a\x20\x22mx9eqve5l2ipgyk\x22\x7d'))
SharingModel.init_file()
$('emsnippet-9911dfc627e1d541').innerHTML = 'test\x2etxt'.em_snippet(50, 0.750).escapeHTML();
$('emsnippet-add7879f5d805012').innerHTML = 'test\x2etxt'.em_snippet(20, 0.750).escapeHTML();
$('emsnippet-981ac0639529f983').innerHTML = 'test\x2etxt'.em_snippet(20, 0.750).escapeHTML();
FilePreview.init_text('https\x3a\x2f\x2fdl\x2edropbox\x2ecom\x2fs\x2fmx9eqve5l2ipgyk\x2ftest\x2etxt', 0)                        });
                    } else if (window.jQuery) {
jQuery(function () {
SharingModel.init('test\x2etxt', Util.from_json('\x7b\x22item\x5fid\x22\x3a\x20\x22\x22\x2c\x20\x22secure\x5fhash\x22\x3a\x20\x22\x22\x2c\x20\x22subpath\x22\x3a\x20\x22\x22\x2c\x20\x22tkey\x22\x3a\x20\x22mx9eqve5l2ipgyk\x22\x7d'))
SharingModel.init_file()
$('emsnippet-9911dfc627e1d541').innerHTML = 'test\x2etxt'.em_snippet(50, 0.750).escapeHTML();
$('emsnippet-add7879f5d805012').innerHTML = 'test\x2etxt'.em_snippet(20, 0.750).escapeHTML();
$('emsnippet-981ac0639529f983').innerHTML = 'test\x2etxt'.em_snippet(20, 0.750).escapeHTML();
FilePreview.init_text('https\x3a\x2f\x2fdl\x2edropbox\x2ecom\x2fs\x2fmx9eqve5l2ipgyk\x2ftest\x2etxt', 0)                        });
                    } 

I cannot get test.txt with command

wget https://www.dropbox.com/s/mx9eqve5l2ipgyk/test.tx


ls -l 
-rw-rw-r-- 1 mirror mirror  30K Sep  6 15:01 test.txt

hugemeow

Posted 2012-09-06T05:14:16.350

Reputation: 1 819

Why WGET? Use CURL = curl https://www.dropbox.com/sh/AAbbCCeeFF123?dl=1 -O -J -L will preserve the folder/filenames + follows redirects. – bshea – 2017-08-15T20:59:09.580

Use youtube-dl – even if you forget to put ?dl=1 at the end (or the link has dl=0), it does the right thing. – unhammer – 2017-12-08T09:31:11.273

Stupid question: were you logged into DropBox when you tried to download using a browser? – None – 2012-09-06T05:23:06.120

1Using wget on your link retrieves test.txt (containing the 4 bytes "test") just fine on my side. Maybe something in your .wgetrc is causing this? – jjlin – 2012-09-06T06:31:02.687

@jjlin what is your command? mine is add above – hugemeow – 2012-09-06T07:02:17.297

5I used wget --no-check-cert https://dl.dropbox.com/s/mx9eqve5l2ipgyk/test.txt. That worked fine for me, but if you want to force a download, you might consider trying wget --no-check-cert 'https://dl.dropbox.com/s/mx9eqve5l2ipgyk/test.txt?dl=1' instead (note the ?dl=1 query parameter). – jjlin – 2012-09-06T15:43:10.250

@jjlin so maybe a script is needed if i want to download file from dropbox:) – hugemeow – 2012-09-06T15:54:05.227

Answers

21

The link in your question is not the link to the file, is a link to the Dropbox page of this file.
If you want to use wget to download it, you should copy the link to direct download from the menu that drops when pushing the download button to the right.

In my case, that worked fine. However, sometimes problems in downloading links from outside the browser relate to parameters other than the link itself. A common element that does not exist when you simply copy the link are the site cookies.

Try this cool FF add-on to get the correct wget links

And also, especially if we are talking about a known workstation and not a casual one, you can of course install the Dropbox client. This will be the easiest way, just let your box be part of your file structure and eliminate the need of complicated downloads.
See this askubuntu.com post, and the Dropbox download page.

amotzg

Posted 2012-09-06T05:14:16.350

Reputation: 911

@amotzg is there a way to resume the download from dropbox with flag --continue? It seems not working to me. (http://unix.stackexchange.com/questions/174850/wget-resume-download-from-dropbox-gives-cant-write-error)

– prayagupd – 2014-12-19T13:36:25.367

@PrayagUpd, found this http://stackoverflow.com/questions/18084677/determine-if-server-supports-resume-get-request.

– amotzg – 2015-01-01T12:25:43.670

1This add-on helped with a shared dropbox link which requires a password to download it. Note, right clicking on the "download" button, selecting cliget gives you the URL to the ?dl=0 output, which is a smaller file. Changing that to ?dl=1 gives the correct download path. – JonTheNiceGuy – 2017-03-02T10:37:39.507

4

Trying to get the direct link in the browser pops up an ad for an upgrade option. I see the other answer (http://superuser.com/a/486351/106977) involving ?dl=1, but that does not allow one to get at the link either (probably due to Box's preventing use unless you upgrade).

– bgoodr – 2013-03-23T14:20:40.980

121

Just add ?dl=1 at the end of the link! For example: https://www.dropbox.com/s/mx9eqve5l2ipgyk/test.txt?dl=1

That should give you a fine retrieval of the file in question without adding anything to the file.

One more thing! If you wanna save the file somewhere else use the -O option like this

wget -O /root/Desktop/test.txt "https://www.dropbox.com/s/mx9eqve5l2ipgyk/test.txt?dl=1"

And if you want to have a little bit of GUI you can use zenity to mark the location to where the file is going to be downloaded!

Here's an example code:

#!/bin/bash
dir=$(zenity --file-selection --directory)
wget -O $dir/test.txt "https://www.dropbox.com/s/mx9eqve5l2ipgyk/test.txt?dl=1"

Ismael Segui

Posted 2012-09-06T05:14:16.350

Reputation: 1 219

Just used your suggestion to get a shared folder, and received an amazing zip file (miss named). Awesome! Thanks a lot!! – Rafareino – 2014-11-15T15:18:06.370

2Much better answer than the accepted one. This helped a lot, thanks. – Seiyria – 2015-09-22T17:08:48.343

4Is this method still working? Using the command wget 'https://www.dropbox.com/sh/my_folder_url?dl=1' I keep getting ERROR 400: Bad Request. – Paul Rougieux – 2016-11-07T09:31:32.443

Now I get 500 Internal Server Error, Dropbox is a real crap. – Avio – 2019-09-17T14:24:16.317

1It works for me. Even today. This solution is better than the answer – TheBlackBenzKid – 2019-11-11T06:39:39.193

1That is awesome, works out of the box... – slotishtype – 2013-12-01T16:11:48.257

15

Dropbox has modified it so that wget will do the right thing and retrieve the file instead of the interstitial.

Use "Share Link" to retrieve the direct link to the file.

Ryan

Posted 2012-09-06T05:14:16.350

Reputation: 151

This should be the correct answer, it's trivial with the share link. – davidparks21 – 2017-01-08T23:04:21.410

Nice! I got a wget: No match output, which was solved using the link enclosed within single quotation marks (due to the ? in the url maybe?) – Matifou – 2017-10-16T18:51:25.713

You sure that is the correct answer. It seems download is only for folks with business account! Please correct me if I am wrong! – chikitin – 2020-02-27T14:25:01.840

3

Saw this question and thought this may help someone trying to download many files at once.

Here's a small Windows CMD/Batch script you can use.
It can easily be adjusted to work under a Bash shell (Mac/Linux/etc).
It uses CURL. WGET should also work with some minor adjustments..

1. Install Curl for Windows.

2. Put the individual SHARED links in a text file (1 per line).

3. Adjust all the "?dl=0" parameter(s) in your text file to "?dl=1" and save.

4. Copy script below to a file called 'geturllist.cmd' (or your choosing)

5. Open a CMD prompt and execute the CMD script.

Downloaded files will appear in current working directory you executed script from.

NOTE:
You must have properly formatted SHARED LINKS that "Anyone with the link" can open. This script does NOT work with password protected links or shares based on a Dropbox login/email.
NOTE:
If the single file or file group(auto zipped) is over a certain size, it will fail with error ("The (zip) file is too large. Please add it to your Dropbox."). In this case you must do as it says.. this script will not work because share link isn't directly downloadable.

Example text file:
("RandomShareCharacters/Here" will be replaced with what it says in share link)

 https://www.dropbox.com/sh/RandomShareCharacters/Here?dl=1
 https://www.dropbox.com/sh/RandomShareCharacters/Here?dl=1
 https://www.dropbox.com/sh/RandomShareCharacters/Here?dl=1

geturllist.cmd:

@echo off
set count=0
setlocal ENABLEDELAYEDEXPANSION
IF [%1]==[] GOTO BLANK
SET PARAMETER=%1
SET _PARAMETER=%PARAMETER:~0,2%

IF [%1]==[/?] GOTO HELP
IF [%1]==[--help] GOTO HELP
IF %_PARAMETER%==-h GOTO HELP

IF EXIST %1 (

  for /f "delims=" %%u in (%1) do (

      set /a count=count+1
      curl -kL "%%u" -O -J

      REM For other share sites:
      REM (ZIP EXAMPLE) if no filename type header sent:
      REM > curl -kL "%%u" -o "!count!.zip"
      REM > echo "!count!.zip"
      REM Will download file(s) called 1.zip, 2.zip, etc.
      )
  ) ELSE (
GOTO BLANK
)
GOTO DONE

:HELP
ECHO.
ECHO    Usage:
ECHO.
ECHO    geturllist [path]\[filename]
ECHO.
ECHO.
ECHO    Required Parameters:
ECHO.
ECHO    [filename]  A text file with one url per line
ECHO    -h      Help
ECHO.
GOTO DONE

:BLANK
ECHO.
ECHO Error: no input file found

:HELPMSG
ECHO.
ECHO Try -h for Help

:DONE
ECHO.
ECHO Exiting.
ECHO.

Example Usage:

geturllist.cmd X:\somepath\dropbox.txt

bshea

Posted 2012-09-06T05:14:16.350

Reputation: 678

1Down-votes with no comments are lovely. Thanks. Hurt your feelings? – bshea – 2017-08-15T20:55:06.113

1Unbelievable why people downvoted this answer ffs, upvoted. – Josyula Krishna – 2018-09-16T10:11:35.117

0

You are gonna get something named "file" or some weird name... Just renaming that file to whatever you want will do the trick. Actually downloaded file is the file you wanted just with weird name and without the file type attribute.

Kruno

Posted 2012-09-06T05:14:16.350

Reputation: 1

-2

The easiest and most guaranteed method for these type of downloads is to use google chrome's developer tools.

  • Press F12 to open developer tools
  • Go to network tab
  • Press the download link to start the download
  • Find the download event in the network events
  • Right click the line and select "Copy as cURL (bash)" or windows if you want

  • The url will look like this:

    curl "http://yoururl.com/yourfile" -H "Pragma: no-cache" -H "Origin: http://yoururl.com" -H "Accept-Encoding: gzip, deflate" -H "Accept-Language: en-US;q=0.8,en;q=0.6,fr;q=0.4" -H "User-Agent: Mozilla/5.0 bla bla" -H "Content-Type: text/plain;charset=UTF-8" -H "Accept: */*" -H "Cache-Control: max-age=0" -H "Referer: http://yoururl.com/downloadpage" -H "Cookie: e07214fb60a1a; _ga=98987; " -H "Connection: keep-alive"
    
  • Replace curl with wget

  • Replace -H "some headers" with --header="some headers"
  • Paste that to your bash window and add the -o parameter. (If you don't add this parameter, the output will be printed to the console.
  • Press enter and enjoy your download.

Hüseyin Yağlı

Posted 2012-09-06T05:14:16.350

Reputation: 167

OP requested usage with wget. – twerdster – 2016-11-14T10:17:40.617

You can easily convert from curl to wget: http://stackoverflow.com/a/25044709/531524

– Hüseyin Yağlı – 2016-11-14T21:42:25.577