The Wayback Machine - https://web.archive.org/web/20241001210431/https://www.geeksforgeeks.org/file-sharing-app-using-python/
Open In App

File Sharing App using Python

Last Updated : 03 Sep, 2021
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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 (the 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.
    • 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)
 
 
# 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.

  • 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.
  • 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.


Previous Article
Next Article

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 generated with the help of Python. Gofile is a platform for sharing and storing files. You have no restrictions on how much content you can save or share. Gofile can accommodate your needs whether
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 using React-Native. A Location Sharing App developed with React-Native allows users to share their real-time location with others. It leverages React-Native's cross-platform capabilities to create a mobile application that facilitates location sharing and tracking among user
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-books, games, etc. The individual users in this network are referred to as peers. The peers request files from other peers by establishing TCP or UDP connections. How Does P2P (Peer-to-Peer) Work?A p
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 distributing media files, having a reliable solution can greatly enhance productivity and convenience. In this article, we'll explore how to create a file-sharing platform using Node.js and Exp
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 prevents a single shareholder from having complete knowledge of the original secret. Thus, the secret is divided into multiple shares and distributed among multiple participants. Therefore, the control ov
5 min read
Implementing Shamir's Secret Sharing Scheme in Python
Secret Sharing schemes are used in the distribution of a secret value among multiple participants (shareholders) by dividing the secret into fragments (shares). This is done in a manner that prevents a single shareholder from having any useful knowledge of the original secret at all. The only way to retrieve the original secret is to combine the sh
7 min read
Dynamic Spectrum Sharing in Wireless Network
Dynamic spectrum Sharing (DSS) is a new emerging technology that allows flexibility to mobile operators for switching between low, mid, and high-band frequencies. It allows both 4G and 5G to share the same spectrum. In this article we are going to learn about the definition of DSS, how it works, all terminologies related to it, what are its disadva
4 min read
Multiplexing (Channel Sharing) in Computer Network
Multiplexing means multiple sources but one link. An alternative approach is a Direct point-to-point connection, but it has several problems as it requires an I/O port for each device, a need line for each device, and also a large amount of wiring needed if on different floors. Instead, if we use a multiplexer approach then all devices are connecte
9 min read
How to save file with file name from user using Python?
Prerequisites: File Handling in PythonReading and Writing to text files in Python Saving a file with the user's custom name can be achieved using python file handling concepts. Python provides inbuilt functions for working with files. The file can be saved with the user preferred name by creating a new file, renaming the existing file, making a cop
5 min read
How to convert PDF file to Excel file using Python?
In this article, we will see how to convert a PDF to Excel or CSV File Using Python. It can be done with various methods, here are we are going to use some methods. Method 1: Using pdftables_api Here will use the pdftables_api Module for converting the PDF file into any other format. It's a simple web-based API, so can be called from any programmin
2 min read
How to convert CSV File to PDF File using Python?
In this article, we will learn how to do Conversion of CSV to PDF file format. This simple task can be easily done using two Steps : Firstly, We convert our CSV file to HTML using the PandasIn the Second Step, we use PDFkit Python API to convert our HTML file to the PDF file format. Approach: 1. Converting CSV file to HTML using Pandas Framework. P
3 min read
How to create a duplicate file of an existing file using Python?
In this article, we will discuss how to create a duplicate of the existing file in Python. Below are the source and destination folders, before creating the duplicate file in the destination folder. After a duplicate file has been created in the destination folder, it looks like the image below. For automating of copying and removal of files in Pyt
5 min read
How to convert a PDF file to TIFF file using Python?
This article will discover how to transform a PDF (Portable Document Format) file on your local drive into a TIFF (Tag Image File Format) file at the specified location. We'll employ Python's Aspose-Words package for this task. The aspose-words library will be used to convert a PDF file to a TIFF file. Aspose-Words: Aspose-Words for Python is a pot
3 min read
Create File Explorer App using React-Native
Creating a File Explorer app using React Native provides a seamless way to explore and interact with the device's file system on both iOS and Android platforms. In this tutorial, we'll guide you through the process of building a simple yet functional File Explorer app. Output Preview: Prerequisites:Node.js and npm installedReact Native CLI installe
3 min read
PYGLET – Opening file using File Location
In this article we will see how we can open a file using file location object in PYGLET module in python. Pyglet is easy to use but powerful library for developing visually rich GUI applications like games, multimedia etc. A window is a "heavyweight" object occupying operating system resources. Windows may appear as floating regions or can be set t
3 min read
Python - Get file id of windows file
File ID is a unique file identifier used on windows to identify a unique file on a Volume. File Id works similar in spirit to a inode number found in *nix Distributions. Such that a fileId could be used to uniquely identify a file in a volume. We would be using an command found in Windows Command Processor cmd.exe to find the fileid of a file. In o
3 min read
Python - Copy all the content of one file to another file in uppercase
In this article, we are going to write a Python program to copy all the content of one file to another file in uppercase. In order to solve this problem, let's see the definition of some important functions which will be used: open() - It is used to open a file in various modes like reading, write, append, both read and write.write() - It is used t
2 min read
File Caching in Distributed File Systems
File caching enhances I/O performance because previously read files are kept in the main memory. Because the files are available locally, the network transfer is zeroed when requests for these files are repeated. Performance improvement of the file system is based on the locality of the file access pattern. Caching also helps in reliability and sca
12 min read
Remote File System (RFS) in File Management
Files can be shared across the network via variety of methods – Using FTP i.e., file transfer protocol is used to transfer file from one computer to other. Using distributed file system (DFS) in which remote directories are visible from local machine. Using Remote File System (RFS) in which the arrival of networks has allowed communication between
2 min read
MoviePy – Getting Original File Name of Video File Clip
In this article we will see how we can get the original file name of the video file in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. Original file name is the name of the original video that existed in the first place i.e which was loaded, even after altering and editing of the vi
2 min read
PyCairo - Saving SVG Image file to PNG file
In this article, we will see how we can save an SVG file to a PNG file using PyCairo in Python. We can create an SVG file using SVGSurface method. An SVG file is a graphics file that uses a two-dimensional vector graphic format created by the World Wide Web Consortium (W3C). It describes images using a text format that is based on XML. SVG files ar
2 min read
Read content from one file and write it into another file
Prerequisite: Reading and Writing to text files in Python Python provides inbuilt functions for creating, writing, and reading files. Two types of files can be handled in python, normal text files and binary files (written in binary language,0s, and 1s). Text files: In this type of file, Each line of text is terminated with a special character call
2 min read
How to get Scrapy Output File in XML File?
Prerequisite: Implementing Web Scraping in Python with Scrapy Scrapy provides a fast and efficient method to scrape a website. Web Scraping is used to extract the data from websites. In Scrapy we create a spider and then use it to crawl a website. In this article, we are going to extract population by country data from worldometers website. Let's i
2 min read
Difference between File Transfer Protocol (FTP) and Secure File Transfer Protocol (SFTP)
Data transfer is the most common task in network and system communications, and they involve transfer of files using two means i.e the File Transfer Protocol (FTP) and the Secure File Transfer Protocol (SFTP). FTP is a commonly applied protocol that enables files to be transferred through a network from one computer to another, but FTP is unsecure
5 min read
Python | Create a stopwatch using clock object in kivy using .kv file
Kivy is a platform-independent GUI tool in Python. As it can be run on Android, IOS, Linux and Windows, etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktop applications. Kivy Tutorial - Learn Kivy with Examples. Clock Object: The Clock object allows you to schedule a function call in
6 min read
Visualizing Tiff File Using Matplotlib and GDAL using Python
Tiff file formats are used for storing raster images. A library called GDAL- Geospatial Data Abstraction Library is specially used for the purpose of reading such raster files along with other file formats like vector formats. The gdal module belongs to Open Source Geospatial Foundation To install this module run this command into your terminal. pi
2 min read
Create a Weather app using Flask | Python
Prerequisite : Flask installation Flask is a lightweight framework written in Python. It is lightweight because it does not require particular tools or libraries and allow rapid web development. today we will create a weather app using flask as a web framework. this weather web app will provide current weather updates of cities searched. Basic setu
2 min read
Weather app using Django | Python
In this tutorial, we will learn how to create a Weather app that uses Django as backend. Django provides a Python Web framework based web framework that allows rapid development and clean, pragmatic design. Basic Setup - Change directory to weather – cd weather Start the server - python manage.py runserver To check whether the server is running or
2 min read
Todo list app using Flask | Python
There are many frameworks that allow building your webpage using Python, like Django, flask, etc. Flask is a web application framework written in Python. Flask is based on WSGI(Web Server Gateway Interface) toolkit and Jinja2 template engine. Its modules and libraries that help the developer to write applications without writing the low-level codes
3 min read
Joke App using Bottle Framework - Python
There are many frameworks in python which allows you to create webpage like bottle, flask, django. In this article you will learn how to create simple app bottle.Bottle is a fast, simple and lightweight WSGI micro web-framework for Python. It is distributed as a single file module and has no dependencies other than the Python Standard Library. Inst
2 min read