Article directory
1 Introduction
As a basic application of the Internet, data sharing and connection are not only widely used in business and office scenarios, but also have strong practical significance for individual users. Because of this, a large number of data sharing software have been developed, and the concept of cloud storage has been repeatedly hyped. For the author who loves to toss, it is also very interesting to find private sharing and storage solutions with the simplest tools. Today, the author will introduce to you how to use a simple programming language like Python to build a shared file server on your own computer, and turn it into a private cloud disk that can be accessed on the public Internet through the data tunnel created by cpolar. .
2. Set up a local file server
As a relatively simple computer language, Python is very popular around the world and has become one of the required courses for beginners of computer technology. Having said so much, in fact, the success of Python comes from its simplicity and powerful functions. For example, now, we can use a few lines of simple code to build a python http.server file sharing server.
2.1.Python installation and settings
First, we need to download a python (you can download it directly from python’s official website www.python.org)
After the download is complete, double-click .exe
the file to install.
During the installation process, remember to add python to the environment variable ( path
) and check the option
Then create a folder to store the files you plan to publish. For convenience of explanation, we name this folderserver
Then run as administrator cmd
and set up python.
First enter it in cmd python
. As long as the following picture appears, it means that python is installed successfully.
Then enter the command line e:
, transfer to the E drive, and then enter the folder you intend to share.
cd server
Finally, enter the command to execute the port output sharing command of the folder.
python -m http.server 9090”(其中端口号可以自选,但必须为未被占用的,可以选择一些偏僻的端口)
After entering the command, a firewall query may appear, we can 允许访问
just click it.
It should be noted that the sharing service function of python is very simple and basic. What is shared here is the folder where the command is currently executed. A certain folder cannot be specified, so we need to change the drive letter and folder first before executing the sharing command.
When you see the above content displayed on cmd, you can access the local 9090 port in the browser, enter it in the address bar localhost:9090
, and access the python shared files.
Due to the simple functionality of python, we cannot close the python process, otherwise the file sharing port will be closed.
2.2.cpolar installation and registration
After completing the python folder sharing settings, we can install and register cpolar to prepare for the subsequent release of shared files. The download address of Cpolar can be found on cpolar’s official website (www.cpolar.com).
On the download page of cpolar, find the corresponding version of the cpolar installation program. The author is using the Windows operating system, so I chose the Windows version to download.
After the download is completed, unzip the downloaded file and double-click .msi
the file to automatically execute the cpolar installation program. We only need to go all the way Next
to complete the installation.
Since cpolar will create an independent data tunnel for each user, supplemented by user passwords and token codes to ensure data security, we need to register users before using cpolar. The registration process is also very simple. Just click on the upper right corner of the cpolar homepage 用户注册
and fill in the necessary information on the registration page to complete the registration.
3. Release of local file server
After completing the python settings, installing and registering cpolar, the remaining work is simple. Just use cpolar to establish a data tunnel. The entrance of the data tunnel is a public Internet address, and the exit is connected to the local python shared file web page.
3.1.Cpolar cloud settings
Since the need to share files may occur at any time, and I don’t want to set up a data tunnel every time I want to share files, I upgraded cpolar to the VIP version in order to retain the data tunnel that can exist stably for a long time (the data created by the free version of cpolar The tunnel resets every 24 hours).
After upgrading cpolar to VIP, we first log in to the cpolar cloud, find 预留
the button on the left side of the customer's main interface, and click to enter the reservation page.
On the reservation page, you can see that cpolar provides data tunnel reservation for multiple protocols, and our python is a web page output, so find the 保留二级子域名
field and set the information in this field.
The set information content is:
地区
: The area where the server is located, just select the nearest one二级域名
: Will eventually appear in the generated public Internet address as one of the identifiers of the network address描述
: Can be seen as a description of this data tunnel, as long as it can be distinguished from other tunnels
After completing these settings, you can click 保留
the button on the right to retain this data tunnel.
If you no longer plan to use this data tunnel, you can click on the right x
to delete it easily to save valuable tunnel quota.
3.2.Cpolar local settings
After completing the retention of the data tunnel entrance in the cpolar cloud, we return to the cpolar local client and connect the data tunnel entrance generated by the cpolar cloud to the local python web page.
First log in to the cpolar client (you can directly access it by typing in the browser localhost:9200
, or click the shortcut of the cpolar client in the start menu), click the - 隧道管理
button on the left side of the client's main interface 创建隧道
to enter the local tunnel creation page (if you want to create The temporary data tunnel that resets the address every 24 hours can be set up directly here instead of setting up a blank data tunnel on the cpolar official website).
On this page, you also need to make several information settings, which include:
隧道名称
: Can be regarded as the local tunnel information annotation of cpolar, as long as it is convenient for us to distinguish协议
: Since python is shared in the form of a web page, selecthttp协议
本地地址
: The local address is the output port number of the local website. Previously, we set the output port of python to 9090, so we also fill it in here.9090
域名类型
: In this example, we have reserved the data tunnel of the second-level subdomain name in the cpolar cloud, so check it二级子域名
(if the reserved domain name is a custom domain name, check the custom domain name), andSub Domain
fill in the next line The reserved second-level subdomain name, in this example is "pythontest". If you plan to create a temporary data tunnel, directly check "Random domain name" and let the cpolar client generate the network address by itself.地区
: The same as the information reserved in cpolar cloud, we can fill it in according to the actual place of use.
After completing these settings, you can click the button below 创建
to complete the construction of this data tunnel that can be retained for a long time.
After the data tunnel is created, cpolar will automatically jump to the 隧道管理
- 隧道列表
page. On this page, we can manage this data tunnel, including opening, closing, or deleting this tunnel. We can also click the 编辑
button to modify the information of this data tunnel.
The Python data tunnel entrance (public Internet access address) can be found in 状态
- 在线隧道列表
.
4. Public network access test
When we paste this 公网地址
into the browser on other devices, we can see the file sharing web page generated by python on the local computer, and can easily view the shared files.
5 Conclusion
So far, we have successfully used cpolar intranet penetration to publish a python file sharing webpage. Although this python file sharing webpage is too simple and has rudimentary functions, it can demonstrate well that the web page (or software) output port is connected to the cpolar data tunnel. The relationship between the port settings, that is, the output port of the web page (or software) must be consistent with the port filled in the cpolar data tunnel, so that the public Internet address and the local web page (or software) can be accurately connected.
Reprinted from cpolar pole cloud article: Python one line of code to achieve file sharing [Intranet penetration through public network access]