How To Send Files Using Python Built-In Http Server Last Updated : 27 Mar, 2024 Comments Improve Suggest changes Like Article Like Report Python's built-in HTTP server offers a straightforward way to share files over a local network or the internet without the need for complex setups. In this tutorial, we'll walk through the step-by-step process of using Python's built-in HTTP server to send files to clients. Setting Up the HTTP ServerThe first step is to start the HTTP server. Open your terminal or command prompt and navigate to the directory containing the files you want to share. Then, execute the following command: python -m http.server Accessing FilesOnce the server is running, any files in the current directory can be accessed by clients. Clients can use a web browser or an HTTP client to access the files by navigating to the server's URL followed by the file name. For example, if the server is running on localhost and port 8000, and there's a file named example.txt in the directory, it can be accessed at http://localhost:8000/example.txt. Sending a WebPage Using built-in HTTP Server of PythonBelow are step-by-step approaches to send a file in Python using a built-in HTTP server: Step 1: Create an HTML FileCreate an HTML file named index.html with the content you want to display. For example HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My Webpage</title> </head> <body> <h1>Welcome to My Webpage!</h1> <p>This is a sample webpage served using Python's built-in HTTP server.</p> </body> </html> Step 2: Start the HTTP ServerOpen your terminal or command prompt, navigate to the directory containing the index.html file, and run the following command: python -m http.serverThis command starts the HTTP server on the default port (8000) and serves files from the current directory. Step 3: Access the WebpageOpen a web browser and navigate to the following URL: http://localhost:8000/index.htmlYou should see the contents of the index.html file displayed in the browser, with the title "My Webpage," a heading "Welcome to My Webpage!", and a paragraph with sample text. Output: Comment More infoAdvertise with us Next Article How To Send Files Using Python Built-In Http Server O oceanofknow6flv Follow Improve Article Tags : Python HTTP Practice Tags : python Similar Reads How to Download and Upload Files in FTP Server using Python? Prerequisite: FTP, ftplib Here, we will learn how to Download and Upload Files in FTP Server Using Python. Before we get started, first we will understand what is FTP. FTP(File Transfer Protocol) File Transfer Protocol(FTP) is an application layer protocol that moves files between local and remote f 3 min read How to Deploy Python WSGI Apps Using Gunicorn HTTP Server Behind Nginx This article describes how to deploy a Python WSGI application using Gunicorn and Nginx. Before proceeding with the tutorial, it's a good idea to first familiarize yourself with the terms WSGI, Gunicorn, and Nginx. Web Server Gateway Interface or WSGI is a specification that describes how a web serv 5 min read 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 4 min read Merge PDF stored in Remote server using Python Prerequisites: Working with PDF files in Python There are many libraries for manipulating PDF files in Python but all are using when that all PDF files already downloaded in your local machine. But what if your target PDF files are in Remote server, you have only URLs of files and no required downlo 2 min read Building a basic HTTP Server from scratch in Python In this article, we are going to learn how to set up a simple and local HTTP server using Python. An HTTP server can be very useful for testing Android, PC, or Web apps locally during development. It can also be used to share files between two devices connected over the same LAN or WLAN network. Ins 2 min read How to Upload Files Using Python Requests Library We are given some files and our task is to upload it using request library of Python. In this article, we're going to discover a way to use the requests library to add files in diverse scenarios, such as uploading unmarried documents, multiple files, and documents with extra form statistics Upload F 3 min read How to Upload File in Python-Flask File uploading is a typical task in web apps. Taking care of file upload in Flask is simple all we need is to have an HTML form with the encryption set to multipart/form information to publish the file into the URL. The server-side flask script brings the file from the request object utilizing the r 2 min read File Transfer using TCP Socket in Python In this article, we implement a well-known Protocol in Computer Networks called File Transfer Protocol (FTP) using Python. We use the TCP Socket for this, i.e. a connection-oriented socket. FTP (File Transfer Protocol) is a network protocol for transmitting files between computers over Transmission 4 min read Python | Build a REST API using Flask Prerequisite: Introduction to Rest API REST stands for REpresentational State Transfer and is an architectural style used in modern web development. It defines a set or rules/constraints for a web application to send and receive data. In this article, we will build a REST API in Python using the Fla 3 min read Launch an HTTP Server with a Single Line of Python Code Python, with its built-in capabilities, offers a simple and effective way to do this. With just a single line of code, you can launch an HTTP server to serve files from your local directory. This feature can be incredibly handy for developers, educators, and anyone needing a quick and easy way to sh 2 min read Like