Ronnie Atuhaire's Blog 😎

Ronnie Atuhaire's Blog 😎

Share Files Easily Using Python

Share Files Easily Using Python

Subscribe to my newsletter and never miss my upcoming articles

Hey thereπŸ‘‹, welcome back to my blog. Today, I felt like sharing what every developer might come across one day.

You might want to share heavy files or access a file from another computer and one of the ways is to use Bluetooth which is time-consuming and a hectic process that requires setting up or configuring devices.


What if I told you that you could easily share files and directories across computers with just a few lines of Python and as a web developer, there will be a point when you need to create your own local webserver. Python 3 comes embedded with an inbuilt HTTP server

Wait, What is an HTTP Server ❓

image.png An HTTP or web server processes requests via HTTP, a network protocol used to exchange information on the World Wide Web (WWW).

The main function of an HTTP server is to store, process and deliver web pages to clients. Buckle up because we are about to make a local server.

TL;DR πŸ™‚ Watch

How To Share/Send Files ➰:

πŸš€ First and foremost, make sure you have Python 3
πŸš€ Make sure that the two computers are on the same wifi or LAN
πŸš€ Go to the terminal from the folder you want to share & cd
πŸš€ Start a server with this command:

py -m http.server

πŸš€ Open a new terminal
πŸš€ Type ipconfig
πŸš€ Copy the address of the IPv4
πŸš€ Paste it in the browser address bar followed by :8000
πŸš€Alternatively copy http://localhost:8000/
πŸš€ The server will be running like this:
image.png πŸš€ You should see the files in the shared folder
πŸš€ Now go to the second computer or device:
πŸš€Open browser and type in the IP address of the first machine, along with port 8000 like this http://[ip address]:8000
πŸš€A page will open showing all the files in the directory being shared from the first computer.

Conclusion ♨

That's it! This is very easy to achieve in Python without having to write any function or code: You gotta fall in love with Python. Fix Firewall issues if you encounter any errors:

Just keep in mind that HTTP.server is only for testing things locally. It usually does only basic security checks and shouldn't be used in production.

If you enjoyed the article, kindly share, like, comment and subscribe for alerts.

Ronnie Atuhaire 😎

Share this