2

I am trying to automate file download with cURL. But the file can only be downloaded when you are logged in. The login is a quite standart POST request, which I have looked at in browser network analysis and now how it´s build up. Now how do I do it with cURL so that I get recognised as logged in and can download the file? Because obviously just sending the POST request before downloading won´t work.

2 Answers 2

2

You very likely need to store cookies. The answer by @jsotola is only appropriate for Basic authentication, which is becoming less common. And you said this is a POST request.

Have a look at the -b and -c options. First issue a curl request to log in and save your cookies using the above mentioned options. Then repeat the call to download the file eg:

curl -b /tmp/cookies -c /tmp/cookies <url> ...

The point of using cookies is to store the authentication tokens, without which every call you make is independent from previous requests. Of course it is possible that the website involves Javascript/Ajax and curl will not always do the job.

Bonus: if you try with a browser like Firefox, the Web developer tools can even generate the Curl requests for you.

enter image description here

1
  • Thank you for your answer Commented Jan 28, 2021 at 14:47
1

Try one of these.

curl http://name:[email protected]/full/path/to/file
curl -u name:passwd http://machine.domain/full/path/to/file
1
  • Sadly none of these worked Commented Jan 24, 2021 at 17:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .