Quick Python File sharing Server

Configurare noua (How To)

Situatie

Goal: Create a basic HTTP server to share files over the web, great for quickly sharing files in a project.

Solutie

1. Setup a Simple HTTP Server with Python
Create a Python script called simple_file_server.py:

python

# simple_file_server.py

import http.server
import socketserver

PORT = 8080
DIRECTORY = “files” # Change this to the folder you want to share

# Simple handler that serves files from the given directory
Handler = http.server.SimpleHTTPRequestHandler
Handler.directory = DIRECTORY

# Create and start the server
with socketserver.TCPServer((“”, PORT), Handler) as httpd:
print(f”Serving files from {DIRECTORY} on port {PORT}”)
httpd.serve_forever()

2. Create a Directory to Share Files
Create a folder called files (or whatever name you want to assign to the folder) and place some sample files in there.

mkdir files
echo “Hello World!” > files/hello.txt
echo “Test File” > files/test.txt

3. Run the Server
Now, run the Python file server:

python3 simple_file_server.py
This will start an HTTP server that listens on port 8080 and serves files from the files directory.

4. Access the Files
You can access the shared files from any device on the same network by navigating to:

http://<your-ip>:8080
This will show a simple directory listing of files in the files folder, and you can download them by clicking on the file links.

Tip solutie

Permanent

Voteaza

(4 din 7 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?