Python Sao operation! The command line computer into a server!

I do not know you have not encountered such a situation, is that you sometimes want to transport something on your computer to your phone or Pad, you either need to use the data cable connected to a computer, sometimes even install the various drivers data can be transmitted either need to use third-party tools on the LAN transmission, there is the use of micro-channel file transfer assistant ...
but these operations have some limitations, such as the driver is not installed on a variety of third-party tools suddenly sucker, or suddenly broken network, which the wtf.


However, there is nothing if not Python Well, today small to share with you a technique using a command can turn your computer into a server, so your phone can get your computer files directly. The command is: python3 -m http.server

 

When you complete execution of this command, your computer listens on port 8000, as long as access to the port (mobile phones and computers required in the same local area network), your phone can get into your computer all the files of this:

If you want to use a cell phone or other devices to access files on your computer, you can take a look at the IP address of this computer:

Then use the phone "IP: Port" can be visited:

Access the computer's image:

Pick one:

The computer can also directly view the PDF file:

Of course, you can also directly access the computer's web page:

For large point files can be downloaded directly down:

Then you can slowly enjoy in the local phone offline:

Python's built-in library regressed, right?

Of course, you do not want to listen on port 8000 can be replaced by another, such as:

python3 -m http.server 8900 --bind 127.0.0.1

Python2 command like this:

python -m SimpleHTTPServer 8900

不过,它只能下载不能上传,俺的帅照没办法传到电脑去,那可怎么行?我们已经知道这是 Python 的内置的 http.server ,那么可以继承它,扩展点功能出来,也就是把我们想要的上传功能也给加上去。我们知道,从电脑获取文件的操作是 GET, 从手机端上传文件上去是 POST 操作,所以我们可以去重写这些方法,刚好小帅b在网上看到有人继承了这个模块扩展了这个功能:

运行起来:

通过手机可以访问到:

选择文件:

成功上传文件:

电脑端接收文件:

ok,以上就是今天小编给你分享的小技巧,使用它可以抛掉各种第三方工具和驱动,自己爱咋传咋传。哦,对了,说个题外话,听说 SOHO 大佬潘总要开始学习 Python 了,谁认识他啊,我特意准备了大量的PDF书籍、视频教程!包括Python软件工具和2019最新入门到实战教程,(http://b6i.cn/3wnpp)复制到浏览器打开即可看到!叫他有空的时候打开看一下!

潘总说得对,哈哈,那么,我们下回见,peace!

Guess you like

Origin www.cnblogs.com/chengxyuan/p/12039754.html