Python Tip: Use the command line of your 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.
Python Tip: Use the command line of your computer into a server
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
Python Tip: Use the command line of your computer into a server
When you finish execute 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 to you All of the files on the computer:
Python Tip: Use the command line of your computer into a server
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:
Python Tip: Use the command line of your computer into a server
then use the phone "IP: port" can be visited:
Python Tip: Use the command line of your computer into a server
access computer in the picture:
Python Tip: Use the command line of your computer into a server
pick one:
Python Tip: Use the command line of your computer into a server
you can also view PDF files directly to the computer:
Python Tip: Use the command line of your computer into a server
of course, you can also directly access the computer's web page:
Python Tip: Use the command line of your computer into a server
for large point files can also be downloaded directly down:
Python Tip: Use the command line of your computer into a server
then you can at the local off-line phone slowly appreciate:
Python Tip: Use the command line of your computer into a server
Python 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 Tip: Use the command line of your computer into a server
However, it can not only download upload, I handsome photos to a computer can not go, then how can the line? We already know that this is Python's built-in http.server, so it can be inherited, function extension points out, that is, we want to also upload feature to add to. We know that to get files from your computer is operating GET, up from the mobile terminal to upload files is POSToperating, so we can go and override these methods, just Xiaoshuai b in line to see someone inherits this module extends this functionality:
Python Tip: Use the command line of your computer into a server
up and running:
Python Tip: Use the command line of your computer into a server
can be accessed by phone to:
Python Tip: Use the command line of your computer into a server
select a file:
Python Tip: Use the command line of your computer into a server
Python Tip: Use the command line of your computer into a server
the file uploads successfully:
Python Tip: Use the command line of your computer into a server
computer terminal to receive the file:
Python Tip: Use the command line of your computer into a server
Python Tip: Use the command line of your computer into a server
the ok, more than that today small for you to share tips with which you can throw away the tools and various third-party drivers, their own love ye ye pass pass.

Guess you like

Origin blog.51cto.com/14623822/2458644