HTTP

Share Files Using Lightweight Http Servers in Linux

Lightweight server applications in Linux can be used to quickly share files between two or more devices. These web server applications are not suitable for advanced web applications that require tighter security, authentication and performance. However, they are perfectly fine if you want to use them to temporarily share files locally or remotely between multiple devices. This article will list some of these static HTTP server applications. So let’s jump in.

SimpleHTTPServer

Simple HTTP server is a built-in python module that can be used to launch a lightweight server suitable for running basic web applications and lightweight file server. As it is a built-in module, it comes pre-installed on almost all Linux distributions having Python installed by default.

Simple HTTP server serves all the files located in the folder it is run from. Run the following commands in succession to launch a simple HTTP server in the “Downloads” folder located in your home directory (commands below are for Python 3 only).

$ cd $HOME/Downloads
$ python3 -m http.server

To run the server on a different port, run the following command instead (change port number according to your requirements):

$ python3 -m http.server 8080

You will see following terminal output on successful launch of the server:

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

If you click on the URL mentioned in the terminal output shown above, you will be able to see a basic file browser layout in the web browser (also on http://localhost:8000/):

To share files with a different device, you have to use a URL in the “http://ip_address:8000/” format. To find IP address of of your computer where simple HTTP server is running, run the command below:

$ hostname -I

You will get some output like this:

192.168.0.107

Enter the IP address obtained above in the URL. The correct URL to access the file server now would be: “http://192.168.0.107:8000/”. You can open this URL in any web browser on any device to download the listed files. Below is a screenshot of this URL opened on an Android device:

To stop the server anytime, press <CTRL+C> while the terminal window is in focus.

HTTP-Server (Node.js)

Http-server is a Node.js module that allows you to run a simple, easy to use and configurable web server. You can use the http-server module to share files from any folder on your system.

To install Node.js on Ubuntu, run the command below:

$ sudo apt install nodejs

To install http-server module, run the command below:

$ npm install -g http-server

To run the http-server from “Downloads” folder in your home directory, run the following two commands in succession:

$ cd $HOME/Downloads
$ http-server

On successful launch of http-server, you will see some output like this:

Starting up http-server, serving ./
Available on:
http://127.0.0.1:8080
http://192.168.0.107:8080

You can now use the second URL listed in the output above to open the file browser in a web browser.

To stop the server anytime, press <CTRL+C> while the terminal window is in focus.

Twistd

Twistd is a simple web server that comes with the “Twisted” python module. It can be used to launch a server that uses http or ftp protocol for sharing files. To install twisted in Ubuntu, run the command below:

$ sudo apt install python3-twisted

To run the twistd from “Downloads” folder in your home directory, run the following two commands in succession:

$ cd $HOME/Downloads
$ twistd3 -n web --path .

On successful launch of web server, you will get some output in the terminal like this:

[-] Site starting on 8080

You can now use a URL in the “http://ip_address:8080/” format. To see IP address of your system, run the command below:

$ hostname -I

You will get some output like this:

192.168.0.107

Enter the IP address obtained above in the URL. The correct URL to access the file server now would be: “http://192.168.0.107:8080/”. You can open this URL in any web browser on any device to download the listed files. Below is a screenshot of this URL opened in Firefox web browser on Ubuntu:

To stop the server anytime, press <CTRL+C> while the terminal window is in focus.

Httpd (Ruby)

Httpd is a lightweight server that comes with the default Ruby package on most Linux distributions. In terms of functionality, it is on par with Python’s simple HTTP server.

To install Ruby on Ubuntu, run the command below:

$ sudo apt install ruby

To run the Ruby httpd from “Downloads” folder in your home directory, run the following two commands in succession:

$ cd $HOME/Downloads
$ ruby -run -e httpd . -p 8000

On successful launch of web server, you will get some output in the terminal like this:

INFO WEBrick::HTTPServer#start: pid=3897 port=8000

You can now use a URL in the “http://ip_address:8000/” format. To see IP address of your system, run the command below:

$ hostname -I

You will get some output like this:

192.168.0.107

Enter the IP address obtained above in the URL. The correct URL to access the file server now would be: “http://192.168.0.107:8080/”. You can open this URL in any web browser on any device to download the listed files. Below is a screenshot of this URL opened in Firefox web browser on Ubuntu:

To stop the server anytime, press <CTRL+C> while the terminal window is in focus.

Conclusion

These are a few lightweight web server applications that are easy to use and can be used to share files publicly. If you want to share files over a network with higher security and authentication standards, these applications may not be suitable and avoid using them in production.

About the author

Nitesh Kumar

Nitesh Kumar

I am a freelancer software developer and content writer who loves Linux, open source software and the free software community.