Commands.page Logo

Ubuntu Command to Download File With HTTPS Proxy Only

This article provides a direct solution for downloading files on Ubuntu when network traffic must be routed through a specific proxy server for HTTPS connections. It outlines the exact command-line syntax required to isolate proxy settings to secure HTTP traffic while leaving standard HTTP requests unaffected.

To download a file using a specific proxy for HTTPS only, use the wget command with the --https-proxy flag. This ensures that only the secure connection to the target server passes through the proxy, while other traffic remains direct. The basic syntax is as follows:

wget --https-proxy=http://proxy_address:port https://example.com/file.zip

Replace proxy_address with the IP address or hostname of your proxy server and port with the corresponding port number. The URL at the end should be the direct link to the file you wish to download. If your proxy requires authentication, include the username and password in the proxy URL like this: http://username:password@proxy_address:port.

Alternatively, you can use the curl command, which is another standard tool available on Ubuntu. To achieve the same result with curl, use the --proxy flag combined with the HTTPS target URL. While curl often handles proxying based on the target URL scheme, explicitly defining the proxy ensures consistency:

curl --proxy http://proxy_address:port -O https://example.com/file.zip

The -O flag tells curl to save the file using its remote name. For temporary sessions where you do not want to modify the command itself, you can set the https_proxy environment variable specifically for the command execution. This method applies the proxy setting only to that specific instance:

https_proxy=http://proxy_address:port wget https://example.com/file.zip

This approach is efficient for scripts or one-off downloads where configuring global proxy settings is unnecessary. Ensure that the proxy address is reachable from your Ubuntu machine before executing the command to avoid connection timeouts.