程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

How Python starts the HTTP server in one second

編輯:Python

Sometimes we have such a need , Local files or remote files need to be sent through the remote terminal FTP After downloading the tool , Then pass it on to others through some social software , This is a little time-consuming and laborious , If I tell you to use Python can 1 Seconds to start one http File download server , And then ip and port Tell others , Let others download it manually according to their own needs , Is this more convenient ?

So how to quickly start a file download server ?

In fact, you only need to execute the following commands in a local directory :

  • Python2
python -m SimpleHttpServer
  • Python3
python3 -m http.server

Local directory structure :

$ ls go
$ bin pkg src

The starting effect is as follows :

$ python3 -m http.server
Serving HTTP on :: port 8000 (http://[::]:8000/) ...
::1 - - [22/Feb/2022 08:52:43] "GET / HTTP/1.1" 200 -


At this point, the browser accesses the corresponding http://ip:port( The default is :http://0.0.0.0:8080), You can download the required files directly on the browser

Tips:

  • Because it starts a HTTP Server, So if there is index.html file , The file will be displayed on the browser by default , If there is no such file , Only the structure of the directory will be displayed
  • Under the same LAN, you can use the default address to access , If you are an Internet user, you need to use intranet penetration to access and download

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved