Run a python one-liner webserver to grab files - last modified 2021-02-23
NOT TO BE USED AT PRODUCTIVE SYSTEMS! You have to read, understand and accept the disclaimer .
Sometimes one needs to access resources from a linux-machine, where you do not want to setup a permanent share of some kind.
As python is preinstalled at all relevant linux distros, one can make use of a basic built-in webserver to temporarily share files. It's enough to switch to a directory one needs to access at the host and run there a python one-liner.
With python 2 run:
python2 -m SimpleHTTPServer 8080
With python 3 run:
python3 -m http.server 8080
Note: you should not need - and try to avoid - to run the command using sudo, as this would make root being the owner of the temporary webserver.
A short test using a web-browser at the host-machine should list the related files/folders for: http://localhost:8080
Using the IP (or a resolvable name) of the host-machine, adding the used port (8080) to the url http://<the-host-machine>:8080 will list files and subdirectories for downloaded the same way at the client.
To stop/interrupt the webserver, it's enough to press CTRL+C at the host-machine.
WARNING/HINT: the simple webserver will be exposed to all network interfaces. Thus it should NOT be used at machines being exposed to the internet.
If the firewall at the host-machine is blocking incoming connections, you could temporarily turn off the firewall, grab your files, and turn the firewall back ON again afterwards.
systemd firewalld service commands
#check firewall-state sudo systemctl status firewalld.service # turn firewall off sudo systemctl stop firewalld.service #turn firewall on sudo systemctl start firewalld.service
ufw - systemd service commands
#check firewall-state sudo systemctl status ufw.service # turn firewall off sudo systemctl stop ufw.service #turn firewall on sudo systemctl start ufw.service
ufw - (older) service commands
#check firewall-state sudo service ufw status # turn firewall off sudo service ufw stop #turn firewall on sudo service ufw start
Good luck - have fun.