14

I am trying to download two files by the following syntax:

curl -O http://domain/path/to/{file1,file2}

The problem is that only the first file is actually saved locally, and the second was simply printed to stdout.

I do realized that if I add a -O it works just fine:

curl -OO http://domain/path/to/{file1,file2}

But isn't this impractical if the number of files grows too big? For example,

curl -O http://domain/path/to/file[1,100]

My question is, is there really no way to download multiple individual files at once with curl (without adding a correct number of -O)?

  • 1
    Why not using a for loop or using wget instead? – Rui F Ribeiro Nov 15 '15 at 12:20
  • 1
    @RuiFRibeiro (1)Yes, I can use loop. I'm just curious if curl can achieve it. (2) I'm considering not only HTTP(s), FTP protocols, e.g. SFTP. – Naitree Nov 15 '15 at 12:25
  • I mean, being such a powerful tool, why curl just fails at this not-so-hard functionality? – Naitree Nov 15 '15 at 12:29
  • 1
    Just to make clear that the {} and [] (and also * and ?) syntax is shell globbing/expansion, curl never gets to see them, it is the same as curl url1 url2 – vonbrand Nov 15 '15 at 13:36
  • wget does not handle SSL – MikeW Aug 15 '17 at 12:33
6

Update: This has been implemented in curl 7.19.0. See @Besworks answer.

According to the man page there is no way to keep the original file name except using multiple O´s. Alternatively you could use your own file names:

curl http://{one,two}.site.com -o "file_#1.txt"

resulting in http://one.site.com being saved to file_one.txt and http://two.site.com being saved to file_two.txt.

or even multiple variables like

curl http://{site,host}.host[1-5].com -o "#1_#2"

resulting in http://site.host1.com being saved to site_1, http://host.host1.com being saved to host_1 and so on.

17

I realize that there is already an accepted answer to this question but I feel I should point out that there actually is a way to do this.

The --remote-name-all option tells curl to behave as if you used -O or --remote-name for each file.

https://curl.haxx.se/docs/manpage.html#--remote-name-all

This option has been available since version 7.19.0

https://curl.haxx.se/changes.html#7_19_0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.