When downloading files with aria2c, the tool typically follows HTTP redirects and saves the file under the name specified by the final URL after all redirects. However, if you want to save the file under the original name (i.e., the name in the URL before any redirects), you can use the --out (or -o) option to explicitly specify the output filename.
Here’s how you can do it:
Steps to Save a File Under the Original Name
Identify the Original Filename:
Look at the original URL you are downloading from. The filename is usually the last part of the URL path (before any query parameters, if present).
For example, if the original URL is https://example.com/downloads/file.zip, the original filename is file.zip.
Use the --out Option:
Use the --out (or -o) option in aria2c to specify the desired output filename, overriding the default behavior of using the redirected filename.
Example
Suppose you are downloading a file from a URL like this:
bash
aria2c https://example.com/download?file=file.zip
If the URL redirects to something like https://cdn.example.com/actual-file.zip, aria2c would normally save the file as actual-file.zip. To save it as file.zip instead, use:
Automatic Filename Detection: If you don’t want to manually specify the filename, aria2c does not have a built-in option to automatically use the original URL’s filename after redirects. You would need to script this behavior (e.g., using a shell script to parse the original URL and pass the filename to --out).
Scripting Example (Optional):
If you are downloading multiple files and want to automate this, you can use a shell script to extract the original filename. For example, in Bash:
This script extracts the filename from the URL (ignoring query parameters) and passes it to aria2c.
Content-Disposition Header: If the server provides a Content-Disposition header with a filename, aria2c may use that instead. To ignore the server’s suggested filename and enforce your own, the --out option will still work.
Summary
To save a file under the original name (before redirects) with aria2c, use the --out option to explicitly specify the desired filename. If you need to automate this for multiple downloads, consider scripting the filename extraction from the original URL.