Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use python to set up a file server

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you how to use python to set up a file server, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Overview

There are a lot of interesting tools integrated inside Python. Today we'll take a look at how to use python's built-in download server to transfer files. Here we will learn:

Start a server in 1 second

Use the browser or download command to download files on the server

Set up a server

Change to the directory where the files are stored and enter the following command under windows or linux to start a server:

If the current system is using the following version of python3, the command is:

Python-m SimpleHTTPServer

If the current system is using python3, the command is:

Python-m http.server

Entering the above command will start a file download server in the current directory, using port 8000 by default. After setting up the server, just tell the IP address and port number to the friend who wants to download the file on the server, and let the friend use the browser or command to download the file, which is very convenient.

Example:

$python3-m http.serverServing HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/).

Note: the directory (or folder) in which you run the above command will use the contents of that directory as the root of the server's download page. Enter the command python3-m http.server-h for more help on this command.

Use a browser to download files on the server

After the server is established, we can use the mobile phone under the same LAN and the browser on the computer to open the download interface on the server:

(if you don't know the IP address of your computer, try logging in to the router or typing the command ifconfig)

Yes, the current interface is very simple. We see the list of files that can be downloaded under the current directory. Click on the list to start the download. How convenient!

If you know the HTML syntax, you can write a file named index.html in the current directory. When you open the download page using a browser, the contents of the index.html file will be displayed by default, such as making a confession animation for the girl you like.

Use the wget command to download the file

If your device does not have a screen or a browser, you can use the command to download files on the server. The wget command under linux does this:

$wget http://192.168.0.102:8000/ uses pytons to build a command line tool. Md is connecting 192.168.0.102 Vl8000. Connected. A HTTP request has been issued Waiting for a response. 200 OK length: 471 [text/markdown] is being saved to: "use pytons to build command line tools .md" use pytons to build command line tools [= >] .471 -.-- 0.007s2021-10-17 00:25:11 (67.0 KB/s)-saved "build command line tools using pytons" .md "[471 KB/s]) above All the contents of the article "how to use python to set up a file server" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report