使用curl通过共享链接(而非公共链接)下载Dropbox文件夹 [英] Use curl to download a Dropbox folder via shared link (not public link)

查看:217
本文介绍了使用curl通过共享链接(而非公共链接)下载Dropbox文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dropbox使得通过curl(EX:curl -O https://dl.dropboxusercontent.com/s/file.ext)以编程方式下载单个文件变得容易.对于文件夹(常规目录文件夹,未压缩)而言,它有点棘手.文件夹的共享链接(而不是文件)不会直接链接到压缩文件夹(Dropbox在下载之前会自动压缩该文件夹).似乎您可以将?dl=1添加到链接的末尾,因为这将直接在浏览器中开始下载.但是,这指向重定向到实际zip文件夹的中间html文档,并且似乎不适用于curl.无论如何,是否可以使用curl通过共享链接下载文件夹?我认识到最好的解决方案是使用Dropbox api,但对于此项目,使其尽可能简单是很重要的.此外,该解决方案必须合并到bash shell脚本中.

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.

推荐答案

使用-L选项,似乎确实可以使用curl.这将强制卷曲遵循重定向.此外,指定扩展名为.zip的输出名称也很重要,因为默认名称将是不带扩展名的随机字母数字名称.最后,不要忘记将?dl=1添加到链接的末尾.没有它,curl将永远无法到达重定向页面.

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

这篇关于使用curl通过共享链接(而非公共链接)下载Dropbox文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆