32

I have tried to download a file from https://logz.io/sample-data.

curl -O https://logz.io/sample-data

However, it just returns an empty file named sample-data.

In contrast to curl, however, wget works well returning a file containing proper contents.

wget https://logz.io/sample-data 

What have I missed with curl?

heemayl
  • 93,925
user3523935
  • 455
  • 2
  • 6
  • 10

1 Answers1

54

You've missed to follow redirections with curl as the URL endpoint is redirected (301) to another endpoint (https://s3.amazonaws.com/logzio-elk/apache-daily-access.log); sending a request with HEAD method (-I) to the specified URL:

% curl -LI https://logz.io/sample-data
HTTP/1.1 301 Moved Permanently
...
...
Location: https://s3.amazonaws.com/logzio-elk/apache-daily-access.log
...

HTTP/1.1 200 OK
...
...
Server: AmazonS3

As curl does not follow HTTP redirections by default, you need to tell curl to do so using the -L/--location option:

curl -LO https://logz.io/sample-data

As wget follows redirections by default, you're getting to the eventual URL with wget as-is.

heemayl
  • 93,925