Use curl to download a Dropbox folder via shared link (not public link)

前端 未结 2 1256
南笙
南笙 2021-02-01 13:04

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 fo

2条回答
  •  暖寄归人
    2021-02-01 13:13

    1. Follow redirects (use -L). Your immediate problem is that Curl is not following redirects.

    2. Set a filename. (Optional)

      • Dropbox already sends a Content-Disposition Header with its Dropbox filename.
        There is no reason to specify the filename if you use the correct curl flags.
      • Conversely, you can force a filename using something of your choosing.

    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).

    • This same line works for both individually shared files or entire folders.
    • Folders will save as a .zip automatically (based on folder name).
    • Don't forget to change the parameter ?dl=0 to ?dl=1 (see comments).

    OR:

    curl https://www.dropbox.com/sh/AAbbCCEeFF123?dl=1 -L -o [filename]
    

    Follow redirect (-L) and sets 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.

提交回复
热议问题