How to Pass Cookies to aria2?
This article provides a practical guide on how to pass authentication cookies to the aria2 command-line download utility. When downloading files from websites that require a login, providing session cookies is essential to prevent “403 Forbidden” or “401 Unauthorized” errors. Below, you will find the specific command-line flags required, methods for exporting cookies from your web browser, and examples of how to format your download commands.
Using the --header
Flag
The most direct way to pass a cookie to aria2 is by injecting it into
the HTTP request header using the --header option. This is
ideal for quick, one-off downloads where you already have the specific
cookie string copied.
The syntax requires you to pass the Cookie: attribute
followed by the key-value pairs of your session tokens.
aria2c --header="Cookie: session_id=xyz123; user_token=abc456" "https://example.com/protected-file.zip"Using the
--load-cookies Flag
For websites with complex authentication or multiple tracking cookies, exporting a cookie file from your browser is the most efficient approach. aria2 can natively read cookie files formatted in the standard Mozilla/Netscape format.
Step 1: Export Cookies from Your Browser
You can use browser extensions to export your active session cookies
into a text file (usually named cookies.txt).
- Chrome/Edge: “Get cookies.txt LOCALLY” or “EditThisCookie”
- Firefox: “Export Cookies”
Step 2: Run the aria2 Command
Once you have saved the file, use the --load-cookies
flag to point aria2 to the path of your exported file.
aria2c --load-cookies=cookies.txt "https://example.com/protected-file.zip"Handling Cookies in Input Files
If you are batch-downloading multiple links using an input text file
(-i or --input-file), you can define cookies
globally for all links in that session, or specify them per URL within
the input file itself.
Global Cookies for Input Files
To apply the same cookie file to every URL listed inside
links.txt:
aria2c --load-cookies=cookies.txt -i links.txtInline Cookies per URL
If the URLs in your text file come from different websites requiring different authentication, you can format your input file to specify options on the lines directly beneath the target URL:
https://site1.com/file1.zip
header=Cookie: session=site1_token_here
https://site2.com/file2.zip
header=Cookie: session=site2_token_here
Important Considerations
- Cookie Expiration: Cookies are time-sensitive. If your download fails after a certain period, your session may have expired, requiring you to re-login to the website and export a fresh cookie string or file.
- Security: Treat your cookie strings and files like passwords. Anyone with access to your active session cookies can impersonate your account on that specific website. Always delete temporary cookie files after your download completes.