One line of code to achieve file sharing

On a LAN, you need to share the contents of a folder.

We can quickly set up an HTTP service on any computer with Python and then share the contents of the files in the folder. Yes, just one line of code

It’s that simple

The related project files of the computer are shared out through THE HTTP protocol, so that other users in the LAN can directly access and download through the IP address.

1. Content to share

IP address: 192.168.0.111 Folder: fileCopy the code

Python one-click sharing

To share code

PS D:\file> python -m http.server 9090 
Copy the code

3. Sharing effect

4. Direct access through HTTP

In the browser, directly access the shared address + port, you can access the shared folder, and you can download.

The browser open http://192.168.0.111:9090Copy the code

Parameters,

--bind: indicates the IP address and port to be bound. The default is the local IP address and the default port is 8080Copy the code

PS D:\> python -m http.server -h
usage: server.py [-h] [--cgi] [--bind ADDRESS] [port]

positional arguments:
  port                  Specify alternate port [default: 8000]

optional arguments:
  -h, --help            show this help message and exit
  --cgi                 Run as CGI Server
  --bind ADDRESS, -b ADDRESS
                        Specify alternate bind address [default: all
                        interfaces]
PS D:\>
Copy the code