Today we going touch topic, how do you share files between two Linux system using python popular library.
HTTPServer is a child program of socketserver. It creates and listen at the HTTP protocol; using this you can easily share your local files over another computer connected in the same network.
Table of Contents
Installation
Install python3 with pip library before installing this library in your system. If you have any doubt python is installed or not in your system.
Type the following command into your Linux terminal.
$ python -V
Python 3.9.1
As you can see, I already have installed python 3.9.1 in my system. Now we are going to install HTTPServer in our system using the pip library.
$ pip install httpserver
If you got above, same screen and message Successfully installed httpserver-1.1.0 in the bottom of the line. You have successfully installed if any error occurred during installation feel free to put your query into the comment section.
Sharing local files to another Linux System
To share files over another network simply open your terminal and navigate to that location. Don’t worry; I will demonstrate you from scratch.
Step 1:
Note: Skip this step if you already have any file in your system you want to share locally because I am going from scratch.
First, I will create folder name share that I want to share over the network and create trendoceans.txt file inside that folder listed over the network.
$ mkdir share && cd share
$ echo "TrendOceans is Best" > trendoceans.txt
Step 2:
Now open up your Linux terminal at this same location in case if you skipped step 1. Then open your terminal into the directory location whose files you want to share over another computer.
Type the following command into your Linux terminal to start HTTPServer into the current path.
$ python -m http.server 6666
Now get local IP of your system and share it with another person connected in the same network.
In my case, my local IP is 192.168.1.109. To connect my system to the person connected in the same network has to type this IP address into his browser with port, we start the HTTPServer in my case, it is 6666.
As you can see, trendoceans.txt file is listed, which I have created in step 1. Even you can download this file by clicking on it or right-click and select Save link as… from the context menu.
When some new connection made using this IP and port, you can monitor it from the terminal where you started your HTTPServer.
This is all you have to do to share your local files to another system. Suppose you are facing any issues while creating listener from the HTTPServer. Make sure below point is satisfied properly.
- Port is not being used by another program or daemon
- Port is not being blocked by your system (Check out: UFW)
- Local IP is correct or not use hostname -i to find IP of your local system.
- Make sure both systems are connected in the same network.
Conclusion
There are multiple ways to share local files to another system connected locally or globally. If you want to learn more, then feel free to tell us in the comment section.
Innovative tech mind with 12 years of experience working as a computer programmer, web developer, and security researcher. Capable of working with a variety of technology and software solutions, and managing databases.