0% found this document useful (0 votes)
78 views

File Sharing App Using Python - GeeksforGeeks

Uploaded by

netflix2006opi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

File Sharing App Using Python - GeeksforGeeks

Uploaded by

netflix2006opi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

8/4/24, 10:35 AM File Sharing App using Python - GeeksforGeeks

File Sharing App using Python


Last Updated : 03 Sep, 2021
Computer Networks is an important topic and to understand the concepts,
practical application of the concepts is needed. In this particular article, we
will see how to make a simple file-sharing app using Python. An HTTP
Web Server is software that understands URLs (web address) and HTTP
(t he protocol used to view webpages). Python has several packages which
is a collection of modules. And it has several built-in servers. The modules
used in this project are:

The HTTPServer is a socketserver, which creates and listens at the


HTTP socket.
The socketserver modules simplify the task of writing network servers.
The webbrowser module provides us with a high-level interface to allow
and display Web-based documents, simply calling the open() function.
The pyqrcode module is used to generate QR Code in just two lines of
code.
OS module helps for interacting with the operating system. Used for
opening files, manipulate paths, and read all lines in all the files on the
command line.
PyPNG allows PNG image files to be read and written using pure
Python

Step-by-step Approach:

Install third-party modules:

pip install pyqrcode


pip install pypng

Install the dependencies using pip install at the command line.


Importing necessary modules:
http.server and socketserver: To host in the browser.
pyqrcode: To generate QRcode.
Open In App
https://www.geeksforgeeks.org/file-sharing-app-using-python/ 1/8
8/4/24, 10:35 AM File Sharing App using Python - GeeksforGeeks

png: To convert the QRCode into a png file.


OS: To interact with the Operating system.
Assign port and name of the user.
Find Ip address of the PC and convert it to a QR code.
Create the HTTP request.
Display the QR code in browser.

Implementation of the above Approach:

Python3

# import necessary modules

# for implementing the HTTP Web servers


import http.server

# provides access to the BSD socket interface


import socket

# a framework for network servers


import socketserver

# to display a Web-based documents to users


import webbrowser

# to generate qrcode
import pyqrcode
from pyqrcode import QRCode

# convert into png format


import png

# to access operating system control


import os

# assigning the appropriate port value


PORT = 8010
# this finds the name of the computer user
os.environ['USERPROFILE']

# changing the directory to access the files desktop


# with the help of os module
desktop = os.path.join(os.path.join(os.environ['USERPROFILE']),
'OneDrive')
os.chdir(desktop)
Open In App
https://www.geeksforgeeks.org/file-sharing-app-using-python/ 2/8
8/4/24, 10:35 AM File Sharing App using Python - GeeksforGeeks

# creating a http request


Handler = http.server.SimpleHTTPRequestHandler
# returns, host name of the system under
# which Python interpreter is executed
hostname = socket.gethostname()

# finding the IP address of the PC


s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
IP = "http://" + s.getsockname()[0] + ":" + str(PORT)
link = IP

# converting the IP address into the form of a QRcode


# with the help of pyqrcode module

# converts the IP address into a Qrcode


url = pyqrcode.create(link)
# saves the Qrcode inform of svg
url.svg("myqr.svg", scale=8)
# opens the Qrcode image in the web browser
webbrowser.open('myqr.svg')

# Creating the HTTP request and serving the


# folder in the PORT 8010,and the pyqrcode is generated

# continuous stream of data between client and server


with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
print("Type this in your Browser", IP)
print("or Use the QRCode")
httpd.serve_forever()

Output:

Open the python file which has the above code on PC.
This will generate a QR-code.

Either Scan the QR-code or type the IP Address shown in the python
shell in your mobile browser.

Open In App
https://www.geeksforgeeks.org/file-sharing-app-using-python/ 3/8
8/4/24, 10:35 AM File Sharing App using Python - GeeksforGeeks

Share the files with ease by scanning the QR-code that’s generated and
get access to the files in PC, from the mobile browser.

Demonstration:

Why Port 8010 ?

TCP Port 8010 use a defined protocol to communicate depending on the


application. A protocol is a set of formalized rules that explains how data is
communicated over a network. This is secured and is not infected by
Virus/Trojan.

Explanation:

The code finds the name of the USERPROFILE through OS module. And
changes the directory to access the files on the desktop.

Open In App
https://www.geeksforgeeks.org/file-sharing-app-using-python/ 4/8
8/4/24, 10:35 AM File Sharing App using Python - GeeksforGeeks

Finds the hostname to serve the file in a particular port for secured
sharing.
Then finds the IP address of the system so that we can connect a
particular device.
The IP address is converted into the form of QR-code using the module
pyqrcode for easy use.
The generated image is hosted in a web browser.
Once the device connected to the same network either scanned QR code
or type the IP address can access the files of the system.

Elevate your coding journey with a Premium subscription. Benefit from ad-free
learning, unlimited article summaries, an AI bot, access to 35+ courses, and more-
available only with GeeksforGeeks Premium! Explore now!
Python Basics Interview Questions Python Quiz Popular Packages Python Projects Practice Python AI
Ready to dive into the future? Mastering Generative AI and ChatGPT is your
gateway to the cutting-edge world of AI. Perfect for tech enthusiasts, this
course will teach you how to leverage Generative AI and ChatGPT with
hands-on, practical lessons. Transform your skills and create innovative AI
applications that stand out. Don't miss out on becoming an AI expert –
Enroll now and start shaping the future!

P prad… Follow 17

Previous Article Next Article


Instagram Bot using Python and InstaPy Send message to Telegram user using
Python

Similar Reads
How to do Cloud File Sharing using Python?
In this article, we will see how to share files online using a free, secure
platform called GoFile. We can make it available for anyone through the link…
4 min read

Create a Location Sharing App using React-Native


In this article, we are going to build a step-by-step Location Sharing App
Open In
using React-Native. A Location Sharing App
App developed with React-Native…
https://www.geeksforgeeks.org/file-sharing-app-using-python/ 5/8
8/4/24, 10:35 AM File Sharing App using Python - GeeksforGeeks
4 min read

P2P (Peer To Peer) File Sharing


In Computer Networking, P2P (Peer-to-Peer) is a file-sharing technology, that
allows users to access mainly the multimedia files like videos, music, e-book…
6 min read

File Sharing Platform with Node.js and Express.js


In today's digital age, the need for efficient File sharing platforms has become
increasingly prevalent. Whether it's sharing documents for collaboration or…
4 min read

Additive Secret Sharing and Share Proactivization - Using Python


A Secret Sharing Scheme is a Cryptographic Scheme that involves the
breaking up of a secret value into multiple fragments/shares in a manner that…
5 min read

View More Articles

Article Tags : Computer Networks Project Python Technical Scripter +2 More

Practice Tags : python

Corporate & Communications Address:- A-


143, 9th Floor, Sovereign Corporate Tower,
Sector- 136, Noida, Uttar Pradesh (201305) |
Registered Address:- K 061, Tower K,
Gulshan Vivante Apartment, Sector 137,
Noida, Gautam Buddh Nagar, Uttar
Pradesh, 201305

Company Languages
About Us Open In App Python
https://www.geeksforgeeks.org/file-sharing-app-using-python/ 6/8
8/4/24, 10:35 AM File Sharing App using Python - GeeksforGeeks
Legal Java
In Media C++
Contact Us PHP
Advertise with us GoLang
GFG Corporate Solution SQL
Placement Training Program R Language
GeeksforGeeks Community Android Tutorial
Tutorials Archive

DSA Data Science & ML


Data Structures Data Science With Python
Algorithms Data Science For Beginner
DSA for Beginners Machine Learning Tutorial
Basic DSA Problems ML Maths
DSA Roadmap Data Visualisation Tutorial
Top 100 DSA Interview Problems Pandas Tutorial
DSA Roadmap by Sandeep Jain NumPy Tutorial
All Cheat Sheets NLP Tutorial
Deep Learning Tutorial

Web Technologies Python Tutorial


HTML Python Programming Examples
CSS Python Projects
JavaScript Python Tkinter
TypeScript Web Scraping
ReactJS OpenCV Tutorial
NextJS Python Interview Question
Bootstrap Django
Web Design

Computer Science DevOps


Operating Systems Git
Computer Network Linux
Database Management System AWS
Software Engineering Docker
Digital Logic Design Kubernetes
Engineering Maths Azure
Software Development GCP
Software Testing DevOps Roadmap

System Design Inteview Preparation


High Level Design Competitive Programming
Low Level Design Top DS or Algo for CP
UML Diagrams Company-Wise Recruitment Process
Interview Guide Company-Wise Preparation
Design Patterns Aptitude Preparation
OOAD Puzzles
System Design Bootcamp
Interview Questions

School Subjects GeeksforGeeks Videos


Mathematics Open In App DSA
https://www.geeksforgeeks.org/file-sharing-app-using-python/ 7/8
8/4/24, 10:35 AM File Sharing App using Python - GeeksforGeeks
Physics Python
Chemistry Java
Biology C++
Social Science Web Development
English Grammar Data Science
Commerce CS Subjects
World GK

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved

Open In App
https://www.geeksforgeeks.org/file-sharing-app-using-python/ 8/8

You might also like