Sometimes, you’re just not in the mood to type out long scp or rsync commands just to pull a file from a remote server. For those quick-and-dirty transfers especially over a local network Python offers a surprisingly handy tool.
With a single command, you can spin up a lightweight HTTP server in the directory containing the file you want, and then download the file via a browser. Here’s how:
Step 1: Start the HTTP Server
Navigate to the directory that contains the file, then run:
python3 -m http.server
By default, this starts a web server on port 8000. You can access the directory listing by visiting:
http://<remote_ip>:8000
Make sure the port is open in any firewall, and you’re okay with anyone on the network accessing these files.
Step 2: Use a Custom Port (Optional)
If port 8000 is occupied or you prefer a different one:
python3 -m http.server 1234
Then visit:
http://<remote_ip>:1234
Step 3: Serve a Different Directory
You can also serve a specific directory using the -d option:
python3 -m http.server -d /path/to/your/directory 1234
This is useful when you’re not in the target folder but still want to expose it.
This method is great for quick transfers over a trusted network. Just fire it up, grab your files via a browser, and move on. For more secure or automated transfers, scp and rsync still remain the better options.