Home Python How to Setup A Basic File server Using simpleHTTPserver In Linux

How to Setup A Basic File server Using simpleHTTPserver In Linux

By sk
Published: Last Updated on 30.1K views

Today, I am going to show you how to turn your desktop system into a local file server in minutes using simpleHTTPserver. simpleHTTPserver is a python module that can be used to setup a file server or serve a directory instantly in LAN. Anyone in the local area network can instantly access the folder or files from your system. Without further ado, let us go ahead and setup a basic file server in minutes using simpleHTTPserver in Linux. This steps should work on any operating systems that supports python.

Setup A Basic File server Using simpleHTTPserver

First, make sure you have installed Python on your Linux box. Python is available in the default repositories of almost all modern Linux operating systems.

On Arch Linux and its derivatives:

$ sudo pacman -S python

On Debian/Ubuntu and its derivatives, run the following command from the Terminal:

$ sudo apt-get install python

RHEL/CentOS:

$ sudo yum install python

Fedora:

$ sudo dnf install python

SUSE/openSUSE:

$ sudo zypper in python

After installing Python, you need to do one more thing. Just run the following command from your Terminal to start the file server:

$ python -m SimpleHTTPServer

For python 3.0 and above versions, run:

$ python -m  http.server 8000

Sample output would be:

Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ..

To stop the file server, just press CTRL+C.

To find Python version, run the following command:

$ python -V

Sample output:

Python 2.7.10

That's it. File server is ready. Open the web browser and point it to http://IP-Address:8000

In case the port 8000 is blocked in your firewall, you have to open it.

For example, on RHEL/CentOS/Fedora, open port 8000 as shown below.

# firewall-cmd --permanent --add-port=8000/tcp
# firewall-cmd --reload

On Debian, Ubuntu you can allow the port as shown below.

$ sudo ufw allow 8000

Here it is how my local server's contents looks in my browser.

Setup A Basic File server Using simpleHTTPserver

Setup A Basic File server Using simpleHTTPserver

As you can see, SimpleHTTPServer serves my current working directory via web browser.

If you want to serve a different directory, just cd into that directory first and then run SimpleHTTPServer like below.

$ cd Downloads
$ python -m SimpleHTTPServer

For python 3.0 and above versions, run:

$ python -m  http.server 8000

Now, the Downloads directory will be served over the network. Anyone in your local network can access your File server and it's contents. Just set the permissions to your files and folders of your choice. You can then browse the contents from any local or remote systems as the way you do in any file server or website.

Disclaimer:

Please be mindful that it is not a full-fledged and secured file server. Python simply allow you to access your desktop/server contents via a web browser. This method is not recommended for production use. Use it within trusted home networks. Also, don't forget to set proper permissions to avoid data loss and misuse.

You May Also Like

2 comments

Richard G. August 12, 2018 - 5:44 pm

This is great and all, but can you recommend ways to setup a file server over any port that doens’t have a GUI?

I had a situation where I had two RHEL/CentOS servers without a GUI. (Command-line only.) I needed to transfer a large file between them. SSH and NFS was blocked between then, but port 80 was open. One of the servers was already listening on port 80, but the other wasn’t.

Normally I would submit a request to our network guy and he’d open the ports I needed. Unforrtunatly he was away on vacation for an entire week. Anyways – I wasn’t sure how to get files between them without SSH or NFS. I’m very dumb when it comes to things like Web stuff. I know it’s possible to have web apps that server files, but have no idea how to find them or how to install/configure them and how to use them (without a GUI) once they’re installed.

Reply
sk August 13, 2018 - 11:30 am

You can simply use this command if port 80 is opened.

sudo python -m SimpleHTTPServer 80

Have a look at here – https://unix.stackexchange.com/questions/24598/how-can-i-start-the-python-simplehttpserver-on-port-80

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More