【python】http.server搭建局域网文件传输

发布时间 2023-05-08 11:28:53作者: 代码诠释的世界

1、起因

    因为测试需要向平板传输apk安装文件,插数据线比较麻烦,同一局域网起个服务方便又快捷,速度也快, linux下类似

 

2、官网文档

    python3.11

    https://docs.python.org/3/library/http.server.html

    python2.7(自行了解)

    https://docs.python.org/2.7/library/simplehttpserver.html?highlight=simpl#module-SimpleHTTPServer

 

3、参数说明

>python -m http.server --help
usage: server.py [-h] [--cgi] [--bind ADDRESS] [--directory DIRECTORY] [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]
  --directory DIRECTORY, -d DIRECTORY
                        Specify alternative directory [default:current directory]

参数也比较好理解

 

4、使用

比如想共享某个目录的文件方便下载, 如桌面文件

 python -m http.server 8000

 

5、访问下载

浏览器输入第4步主机的ip地址,可以通过ipconfig查看

类似FTP, 点击即可下载,需要同一局域网