Tuesday, September 2, 2014

linux - cURL: HTTP file download


I have tried to download a file using curl "https://www.dropbox.com/s/tf7e7vndqd9hv05/Ace_The_IELTS.pdf?dl=0" -o "file.pdf" but it downloads a file which is of few bytes. When I open the link in the browser I see the web page opened with the pdf but not downloaded to my desktop. I guess that curl command is downloading the webpage but not exact pdf file. Can anyone please help me in downloading the file using curl. Am I missing anything? Thanks


Answer



Dropbox file links go to a webpage, that then redirects to the actual content.


The link to the above PDF is actually at


https://dl.dropboxusercontent.com/content_link/v0qPqJrCIS7IvTmXr0pXBFKnnbmZpsRfSNxDhfqcjLg88F7ErNCyNAaOIATPKrWT?dl=1

The easiest way I can think to determine the actual url is to first do:


curl "https://www.dropbox.com/s/tf7e7vndqd9hv05/Ace_The_IELTS.pdf?dl=1" -o "temp.txt"

(note the dl=1)


Then look at the temp.txt:



Found

Found


The resource was found at https://dl.dropboxusercontent.com/content_link/jGdZ7mfVMNV7VCiauE9T7kGpaOyBKyu6i8KaAzqLzUSaEd2ElXllzDeQEC8DCxHr?dl=1;
you should be redirected automatically.




WSGI Server




Then you'll see the correct url.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...