Build a web service with one line of python commands to realize file sharing on the intranet

Build a web service with one line of python commands to realize file sharing on the intranet

Sometimes when we access our own virtual machine on a local computer, we may not be able to directly transfer the CV file to the virtual machine for some reasons. But at this time we want to upload files to the virtual machine, if the virtual machine and the local computer can communicate with each other. Then we can start a web service directly through python.

Prerequisite: This machine needs to have a python environment. python download address: http://python.org/

The port below is the specified port number, and the startup commands for python3 and python2 are different;

  • python2:
python -m SimpleHTTPServer port
  • python3:
python3 -m http.server port

Take python3 as an example:

I want to share files in my local mac/User/cpu directory. Then I need to cd to the /User/cpu directory first, and then execute the command:
python3 -m http.server 80
Insert image description here
Insert image description here

At this point, I can directly select the file I want to download, then right-click and save directly as, to achieve the download effect:
Insert image description here
Result:
Insert image description here
Successfully downloaded

Guess you like

Origin blog.csdn.net/weixin_45565886/article/details/133825548