>_ IzzyLab

Hands-on task

This task is step 2 of the course “curl and HTTP APIs”

Download a file, keeping its name

easy~3 min

The server serves a file at http://localhost/files/report.txt. Download it into the /root directory, keeping the original filename (report.txt) — so you should end up with /root/report.txt.

The server shows up in the Site tab too: the browser will show the file, but you need to save it with curl in the terminal.

What you'll practise:
  • curl
  • http
  • file download
  • filename from url

Topic breakdown

curl has two related saving mechanisms: write the response under a name you choose, or take the name from the last segment of the URL. The second option is handy when you need to save a file under its "native" name. An important detail: when saving by the name from the URL, the file is placed in the current working directory, so the final location depends on where the command is run from.

What's checked

  1. file downloaded under its own name

What it looks like