Save a download with its remote name
Save a download under the name in the URL with curl -O. It writes to the current directory, and a URL that ends in a slash has no name to use.
A download should land in a file called what the URL says, without typing the name twice.
mkdir dl && cd dl
curl -sO http://127.0.0.1:8000/report.txt
ls
curl -sO http://127.0.0.1:8000/
echo "exit: $?"report.txt
exit: 23-O (--remote-name) takes the last path segment of the URL as the file name and saves into the current directory. The option is in the curl manual. When the URL ends in a slash there is no segment, and curl refuses to guess, and the last command exits with status 23 instead of saving anything.
The name comes from the URL, not from the server, so a redirect to a different file name still saves under the first one. Add -J if you want the name from the Content-Disposition header, and keep in mind that -O overwrites an existing file of the same name without asking.