一行代码实现文件共享

在一个局域网内,需要共享一个文件夹里内容。

我们可以在任意一台有python环境的电脑上,迅速架起一个http协议的服务,然后将文件夹里的文件内容共享出来。是的仅仅需要一行代码

就是这么简单

把电脑的相关项目文件通过http协议共享出去,让局域网内的其他用户 通过IP地址就可以直接进行访问和下载。

1、需要共享的内容

IP地址:192.168.0.111

共享文件夹:file

python windows环境下查看共享文件夹 python读取共享文件夹_IP

2、python一键共享

共享代码

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

3、共享效果

python windows环境下查看共享文件夹 python读取共享文件夹_IP_02

4、通过http直接访问

在浏览器中直接访问共享的地址+端口,即可访问共享文件夹,还可以下载。

浏览器打开 http://192.168.0.111:9090

python windows环境下查看共享文件夹 python读取共享文件夹_文件共享_03

参数详解

--bind:绑定的IP 和 端口,默认是本机ip,默认端口是8080
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:\>