Setting up a Basic File server Using simpleHTTPserver

Setting up a Basic File server Using simpleHTTPserver

simpleHTTP title

Introduction

In this article we will demonstrate a quick and easy method to use your local system as a basic File Server using simpleHTTPserver. The SimpleHTTPServer is a built in module that comes available with the default Python installation on a YUM based system. It is a simple HTTP server that provides standard GET and HEAD request handlers. This allows users to access their data over a web browser allowing anyone in the local area network to access files and folders on from the local system. An advantage with the built-in HTTP server is that you don’t have to install and configure anything. The only thing that you need, is to have Python installed. You can use this to turn any directory in your system into your web server directory.

 

Prerequisites:
Since simpleHTTPserver is a built in python module, the only prerequisite for using it is that your system should have python installed. If you are using any modern Linux distribution then python should be installed on your system as part of the base installation.

Let’s verify that we have python installed on our system and check its version.

[root@linuxnix ~]# which python
/usr/bin/python
[root@linuxnix ~]# python -V
Python 2.7.5
[root@linuxnix ~]#

If you are working on a system that does not have python installed then you could install it manually using your system’s package manager.

On Arch Linux and its derivatives:

pacman -S python

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

apt install python

On RHEL/CentOS:

yum install python

On Fedora:

dnf install python

On SUSE/openSUSE:

zypper install python

Using simpleHTTPserver

To use simpleHTTPserver first change to the directory you wish to make accessible via the web browser and then type the follwing command:

[root@linuxnix ~]# python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
192.168.19.1 - - [27/Aug/2018 15:33:42] "GET / HTTP/1.1" 200 -
192.168.19.1 - - [27/Aug/2018 15:33:42] code 404, message File not found
192.168.19.1 - - [27/Aug/2018 15:33:42] "GET /favicon.ico HTTP/1.1" 404 -
192.168.19.1 - - [27/Aug/2018 15:33:52] "GET /.bashrc HTTP/1.1" 200 -

This will make the current working directory browsable via the HTTP protocol on port 8000. Now open the web browser and type in the URL http://:8000. This will display all the files and directories in the current working directory from which the SimpleHTTPServer module was launched. Given below is a screenshot:

simpleHTTP

If you click on any of the files, it will be downloaded to your system.

As long as the HTTP server is running, the terminal will update as data are loaded from the Python web server.  You should see standard http logging information (GET and PUSH), 404 errors, IP addresses, dates, times, and all that you would expect from a standard http log as if you were tailing an apache access log file. To stop the file server, just press CTRL+C.

Conclusion

In this article we demonstrated how easily one could setup a simple file server using pythons’ simpleHTTPserver module. It’s a quick and easy way of serve the contents of the current directory from the command line. Although there are feature reach and specialized web server software like apache, nginx and IIS available in the market, pythons’ built in web server does not require any installation and configuration to get things started. We hope that you’ve found this article to be useful and we look forward towards your suggestions and feedback.

The post Setting up a Basic File server Using simpleHTTPserver appeared first on The Linux Juggernaut.

Basics http LinuxNix Python