需求背景
之前在虛擬機、遠程的服務器,如果因為一些硬性限制,但又想傳輸的檔案的時候,沒有太好的辦法的時候,系統如果默認安裝了Python3,可以使用python自帶的server服務來進行檔案傳輸,
// python 2.X
temp$ python -m SimpleHTTPServer 2020
// python 3.X
temp$ python -m http.server 3030
但是,有個缺點,就是他只能單向傳輸,就是你只能從服務器上拉取檔案回來,但是不能傳輸檔案到服務器,基于這個需求,有了下文的解決方案,
// install , 如果不能上網,可以考慮將代碼下載到本地
git clone https://github.com/freelamb/simple_http_server.git
// 進入你要共享的檔案夾
PS D:\home\code\python\simpy-server> cd .\file\
PS D:\home\code\python\simpy-server\file> ls
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2023/3/20 14:36 0 1.txt
-a---- 2023/3/20 14:37 0 a.txt
-a---- 2023/3/20 14:37 0 test.txt
// run
PS D:\home\code\python\simpy-server\file> python ..\simple_http_server\simple_http_server.py 8989
server_version: simple_http_server/0.3.1, python_version: Python/3.10.2
sys encoding: utf-8
Serving http on: 0.0.0.0, port: 8989 ... (http://0.0.0.0:8989/)
Use the effect demo:

Reference
linux下幾種檔案傳輸的方式介紹
https://www.cnblogs.com/mysticbinary/p/12785763.html
使用python構建簡單的http上傳下載服務
https://www.jianshu.com/p/2147b7e7cf38
Source code
https://github.com/freelamb/simple_http_server
Github:https://github.com/Mysticbinary
君何不暢談一番?
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/547459.html
標籤:Python
上一篇:Python工具箱系列(二十七)
