Uploading files to HTTP or HTTPS endpoints with wget enables automated log forwarding, configuration backups, and simple API integrations from non-interactive scripts. Using a single command-line client for both downloads and uploads simplifies maintenance on remote servers and minimal Linux installations where heavyweight HTTP tooling is not available. Raw file uploads are especially useful for pushing text logs, JSON documents, or small binary objects to services that accept direct request bodies.
The wget client can transmit file contents as the HTTP request body by using options such as --post-file and --body-file, while --method selects the HTTP verb, for example POST or PUT. Custom headers added with --header control metadata like Content-Type so that servers correctly interpret the uploaded data, and --output-document writes responses to local files for inspection, parsing, or error handling in shell scripts.
These upload options require a recent wget version (1.20 or newer for --method and --body-file) and a server endpoint configured to accept incoming request bodies. Direct uploads of this sort are suited to APIs and simple echo services and are not a replacement for browser-style multipart form submissions. Care is essential when using methods like PUT, which many servers treat as full object replacement, because an incorrectly chosen URL can overwrite existing data.
Related: How to send POST data with wget
Related: How to set custom headers in wget requests
Steps to upload a file with wget:
- Create a small text file in the working directory to act as the upload payload.
$ printf 'sample payload from wget\n' > upload-file.txt $ ls -l upload-file.txt -rw-r--r-- 1 user user 27 Dec 7 12:34 upload-file.txt
Any existing file can be used instead of upload-file.txt when sending real data.
- Send the file as an HTTP POST request and capture the JSON response in post-response.json.
$ wget --post-file=upload-file.txt --header='Content-Type: text/plain' --output-document=post-response.json https://httpbin.org/post --2025-12-07 12:40:02-- https://httpbin.org/post Resolving httpbin.org (httpbin.org)... 3.220.52.181 Connecting to httpbin.org (httpbin.org)|3.220.52.181|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 521 [application/json] Saving to: ‘post-response.json’ post-response.json 100%[============================================================================>] 521 --.-KB/s in 0.01s 2025-12-07 12:40:02 (39.5 MB/s) - ‘post-response.json’ saved [521/521]
The URL https://httpbin.org/post is an echo service suitable for testing and can be replaced with an API or upload endpoint in production.
- Upload the same file using the HTTP PUT method to simulate object replacement semantics, writing the reply to put-response.json.
$ wget --method=PUT --body-file=upload-file.txt --header='Content-Type: text/plain' --output-document=put-response.json https://httpbin.org/put --2025-12-07 12:41:15-- https://httpbin.org/put Resolving httpbin.org (httpbin.org)... 3.220.52.181 Connecting to httpbin.org (httpbin.org)|3.220.52.181|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 533 [application/json] Saving to: ‘put-response.json’ put-response.json 100%[============================================================================>] 533 --.-KB/s in 0.01s 2025-12-07 12:41:15 (41.2 MB/s) - ‘put-response.json’ saved [533/533]
Many servers treat PUT requests as full replacements of the object at the target URL, so incorrect paths can overwrite existing data.
- Adjust the Content-Type header for binary uploads by specifying an appropriate media type for the payload.
$ wget --method=PUT --body-file=archive.tar.gz --header='Content-Type: application/octet-stream' --output-document=put-archive-response.json https://example.com/upload/archive
Using the correct Content-Type ensures that APIs and object stores handle files with the expected encoding and validation rules.
- Verify that the uploads succeeded by inspecting the saved JSON response files for the echoed payload.
$ python3 -m json.tool post-response.json | grep '"data"' "data": "sample payload from wget\n", $ python3 -m json.tool put-response.json | grep '"data"' "data": "sample payload from wget\n",A successful test typically includes a 200 OK status in the wget output and a "data" field in the JSON body containing the original contents of upload-file.txt.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.
