-
1.目的:
创建web服务器用于在windows主机和linux虚拟机之间共享文件,可以直接通过浏览器查看linux虚拟机的文件 -
2.创建文件服务:
在linux需要共享的目录下运行命令
python2: python -m SimpleHTTPServer 9999
python3: python3 -m http.server 9999
The SimpleHTTPServer module has been merged into http.server in Python 3.0. The 2to3 tool will automatically adapt imports when converting your sources to 3.0.
-
3.查看共享文件:
在windows浏览器输入"http://192.168.5.67:9999/",即可看到linux共享目录下文件
效果类似如下:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-RoLHlzuC-1609045881579)(https://www.tecmint.com/wp-content/uploads/2015/03/Directory-Listing.jpg)] -
4.从其它位置提供文件服务
如果想提供某个目录的文件服务,但又不进入该目录,可以是使用复合命令
pushd /home/cs/tt/test/pkg/cc; python3 -m http.server 9999; popd;
- 5.提供HTML文件服务
如果在提供文件服务的目录下有index.html,python解释器会自动检测到它,并提供html文件服务(显示网页),而不会提供文件服务
在cc目录下新建index.html文件
index.html:
<html>
<header><title>TECMINT</title></header>
<body text="blue"><H1>
Hi all. SimpleHTTPServer works fine.
</H1>
<p><a href="https://www.tecmint.com">Visit TECMINT</a></p>
</body>
</html>
执行命令
pushd /home/cs/tt/test/pkg/cc; python3 -m http.server 9999; popd;
效果类似如下: