翼度科技»论坛 编程开发 python 查看内容

通过python3启动WEB的方法传输文件

9

主题

9

帖子

27

积分

新手上路

Rank: 1

积分
27
需求背景

之前在虚拟机、远程的服务器,如果因为一些硬性限制,但又想传输的文件的时候,没有太好的办法的时候,系统如果默认安装了Python3,可以使用python自带的server服务来进行文件传输,
  1. // python 2.X
  2. temp$ python -m SimpleHTTPServer 2020
  3. // python 3.X
  4. temp$ python -m http.server 3030
复制代码
但是,有个缺点,就是他只能单向传输,就是你只能从服务器上拉取文件回来,但是不能传输文件到服务器,基于这个需求,有了下文的解决方案。
  1. // install , 如果不能上网,可以考虑将代码下载到本地
  2. git clone https://github.com/freelamb/simple_http_server.git
  3. // 进入你要共享的文件夹
  4. PS D:\home\code\python\simpy-server> cd .\file\
  5. PS D:\home\code\python\simpy-server\file> ls
  6. Mode                LastWriteTime         Length Name
  7. ----                -------------         ------ ----
  8. -a----        2023/3/20     14:36              0 1.txt
  9. -a----        2023/3/20     14:37              0 a.txt
  10. -a----        2023/3/20     14:37              0 test.txt
  11. // run
  12. PS D:\home\code\python\simpy-server\file> python ..\simple_http_server\simple_http_server.py 8989
  13. server_version: simple_http_server/0.3.1, python_version: Python/3.10.2
  14. sys encoding: utf-8
  15. 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

来源:https://www.cnblogs.com/mysticbinary/p/17235819.html
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

举报 回复 使用道具