目錄
問題描述
解決辦法
問題描述
在工作中,我們經(jīng)常遇到文件傳輸這樣的事情,小文件傳輸,一般使用QQ或者微信就能滿足,但當(dāng)傳輸文件幾百MB或者幾十G時,這種傳輸效率就有點捉襟見肘;同時,我們也可以用U盤或者移動硬盤進(jìn)行拷貝,但偶爾移動硬盤滿了或者沒有攜帶時候,就尷尬了。
本文可以用Python搭建一個簡單HTTP服務(wù),在一個局域網(wǎng)內(nèi)可以達(dá)到幾十兆的速度。
解決辦法
python -m http.server格式說明
$ 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]
如果想提供一個下載目錄,例如:/data ;那么在終端命令里面執(zhí)行 cd /data;然后執(zhí)行命令: python -m http.server
默認(rèn)的端口號是8000, 服務(wù)器根目錄就是運行python命令的工作目錄
用http://127.0.0.1:8000即可訪問目錄下內(nèi)容
或者加上端口號:python -m http.server 8000
用http://127.0.0.1:8000即可訪問目錄下內(nèi)容
用Python實現(xiàn)簡單的HTTP服務(wù)器如下三種:
- BaseHTTPServer:提供基本的Web服務(wù)和處理器類,分別是HTTPServer及BaseHTTPRequestHandler;
- SimpleHTTPServer:包含執(zhí)行GET和HEAD請求的SimpleHTTPRequestHandler類;
- CGIHTTPServer:包含處理POST請求和執(zhí)行的CGIHTTPRequestHandler類。
在我目前的實現(xiàn)中,主要采用BaseHTTPServer模塊。
參考網(wǎng)址:文章來源:http://www.zghlxwxcb.cn/news/detail-412089.html
- https://blog.csdn.net/qq_35396598/article/details/88421581
- https://blog.csdn.net/e_Inch_Photo/article/details/80060952
?文章來源地址http://www.zghlxwxcb.cn/news/detail-412089.html
到了這里,關(guān)于python -m http.server 迅速搭建本地任意目錄http.server服務(wù)器的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!