VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > python入门教程 >
  • Python3通过WEB方式双向传输文件

需求背景

之前在虚拟机、远程的服务器,如果因为一些硬性限制,但又想传输的文件的时候,没有太好的办法的时候,系统如果默认安装了Python3,可以使用python自带的server服务来进行文件传输,

// python 2.X 
temp$ python -m SimpleHTTPServer 2020

// python 3.X 
temp$ python -m http.server 3030

但是,有个缺点,就是他只能单向传输,就是你只能从服务器上拉取文件回来,不能传输文件到服务器,基于这个需求,有了下文的解决方案。

// install , 如果不能上网,可以先将代码下载到本地,然后在传输到目标系统
git clone https://github.com/freelamb/simple_http_server.git


// 进入你要共享的文件夹
PS D:\home\code\python\simpy-server> cd .\file\
PS D:\home\code\python\simpy-server\file> ls

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        2023/3/20     14:36              0 1.txt
-a----        2023/3/20     14:37              0 a.txt
-a----        2023/3/20     14:37              0 test.txt

// run
PS D:\home\code\python\simpy-server\file> python ..\simple_http_server\simple_http_server.py 8989
server_version: simple_http_server/0.3.1, python_version: Python/3.10.2
sys encoding: utf-8
Serving http on: 0.0.0.0, port: 8989 ... (http://0.0.0.0:8989/)

Use the effect demo:

Reference

linux下几种文件传输的方式介绍
https://www.cnblogs.com/mysticbinary/p/12785763.html

使用python构建简单的http上传下载服务
https://www.jianshu.com/p/2147b7e7cf38

Source code
https://github.com/freelamb/simple_http_server

 

 

Github:https://github.com/Mysticbinary

出处:
https://www.cnblogs.com/mysticbinary/p/17235819.html


相关教程