You are not logged in.

#1 2019-10-29 00:15

JimW
Member
Registered: 2015-12-08
Posts: 362

Very Simple HTTP server

many, like myself, may not know that they have a very simple HTTP server. If they want to serve up a webpage on their computer or local network they don't need to install Apache or similar.
First - you do need python
You can check if you have it and which version by typing "python" (exit with ctl D)
Should give you something like this:

$ python
Python 2.7.16 (default, Apr  6 2019, 01:42:57)
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>ctl D

as you can see I have version 2.7.16
to start the server simply type:

$ python -m SimpleHTTPServer 8080

the 8080 is the port you will run on. If you do not enter a port it will run on 8000! It will generate an html listing of the folder you are running from.  But if you want to use an index.htm the server will recognize that and use it instead.
Start your web browser and enter localhost:8080 and you should see the listing of whatever is in your folder. This works the same from any local computer, just enter the ip address instead of localhost. For me, I would enter 192.168.1.8:8080
You can now transfer files from your 'server' to other computers on your lan! If you have movies or audio you can watch them on the other computers without having to download them.
The terminal you started the program from is your log, it will show connections and errors. I guess you could re-direct it to a file if you wanted a more permanent record.
When finished just go back to the terminal you started it from and press ctl C to break the program. If you have put it in the background then you would have to find the pid and kill it with the kill command.

WARNING!!
There is no configuration with this program and no security. I would suggest you only use it for short periods and not leave it running!

Note:
if you have python 3.x or above you might try

python -m http.server

Offline

#2 2019-12-21 06:14

DavidB
Member
From: Saskatchewan, Canada
Registered: 2015-12-06
Posts: 140
Website

Re: Very Simple HTTP server

Hey, Jim, thanks for this tip!  I never knew, and this will be dead easy for me when I have to transfer files between my laptop and my wife's!  No more having to go find a USB dongle.


Why do I like using TDE so much?  It follows my philosophy of, "If it ain't broke, don't fix it!"

Offline

#3 2020-01-21 06:56

gatton
Member
Registered: 2020-01-21
Posts: 1

Re: Very Simple HTTP server

This is a super tip that I was completely unaware of. Even lighttpd isn't this simple.
Just FYI on my Q4OS install I needed to use:

python3 -m http.server 8080

Also to clarify when you run this, it will list the contents of whatever directory you are in when you run the command. So make sure you run it in the folder that contains the files you are trying to make available over the network. I didn't see a way to change directories once it's running. Although I imagine you could script this to always have it run in the directory you want.

Offline

Board footer

Powered by FluxBB