使用python实现http及ftp服务进行数据传输的方法
作者:mazhen1991 时间:2021-08-26 01:20:19
服务器之间的http数据传输
直接使用python内置的http服务:
python -m SimpleHTTPServer 8000
此时,输入指令的目录就已经开启了http服务,8000为端口(如不指定,默认为8000),如果我们需要在其他机器下垃取该目录下的文件,只需在目标机器运行:
wget ip:port/文件名
速度杠杆的。
开启ftp上传文件
安装ftp的python第三方组件
pip install pyftpdlib
编写启动脚本
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
import os
def main():
# Instantiate a dummy authorizer for managing 'virtual' users
authorizer = DummyAuthorizer()
# Define a new user having full r/w permissions and a read-only
# anonymous user
authorizer.add_user('user', '12345', '.', perm='elradfmwM')
authorizer.add_anonymous(os.getcwd())
# Instantiate FTP handler class
handler = FTPHandler
handler.authorizer = authorizer
# Define a customized banner (string returned when client connects)
handler.banner = "pyftpdlib based ftpd ready."
# Specify a masquerade address and the range of ports to use for
# passive connections. Decomment in case you're behind a NAT.
#handler.masquerade_address = '151.25.42.11'
#handler.passive_ports = range(60000, 65535)
# Instantiate FTP server class and listen on 0.0.0.0:2121
address = ('', 8888)
server = FTPServer(address, handler)
# set a limit for connections
server.max_cons = 256
server.max_cons_per_ip = 5
# start ftp server
server.serve_forever()
if __name__ == '__main__':
main()
其中8888是我设定的端口号,user是用户名,12345是我指定的密码,此时,我们至需要运行脚本,就可以使用ftp工具,连接该ftp服务器,并上传文件了。
如果我们不使用我们自己编写的脚本,而是直接使用内置的脚本:
python -m pyftpdlib -p 8888
此时,连接该ftp服务器,使用的是默认的用户:anonymous,但是当我们上传文件时,会发现,没有该用户的上传权限,所以,这里建议自己编写运行脚本。
来源:https://blog.csdn.net/mazhen1991/article/details/80579856
标签:python,http,ftp
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
javascript拼音搜索引擎
2011-08-29 15:42:14
轻设计,让网站灵敏轻便的6个技巧
2009-12-07 21:26:00
![](https://img.aspxhome.com/file/UploadPic/200912/7/logo2-92s.gif)
ipython jupyter notebook中显示图像和数学公式实例
2022-06-20 12:19:37
小小聊天室Python代码实现
2022-05-27 15:23:44
python BlockingScheduler定时任务及其他方式的实现
2022-02-13 17:32:25
在Python中使用M2Crypto模块实现AES加密的教程
2022-09-29 17:43:59
Python随机数用法实例详解【基于random模块】
2023-10-26 08:48:49
JavaScript中使用Async实现异步控制
2023-08-23 00:55:54
浅谈Python中用datetime包进行对时间的一些操作
2022-09-27 09:32:14
关于python3的ThreadPoolExecutor线程池大小设置
2023-12-05 13:37:57
golang 微服务之gRPC与Protobuf的使用
2023-06-17 20:36:03
基于Python记录一场2023的烟花
2022-01-08 19:57:07
![](https://img.aspxhome.com/file/2023/1/109651_0s.png)
PID原理与python的简单实现和调参
2021-08-13 13:27:36
![](https://img.aspxhome.com/file/2023/5/85115_0s.png)
php 读取文件头判断文件类型的实现代码
2023-11-15 09:50:06
python 在某.py文件中调用其他.py内的函数的方法
2021-02-25 23:56:09
python中print()函数的“,”与java中System.out.print()函数中的“+”功能详解
2021-12-18 10:27:02
如何对MySQL数据库表进行锁定
2009-02-10 10:39:00
pytorch 实现删除tensor中的指定行列
2023-05-22 14:26:26
Python实现arctan换算角度的示例
2023-07-16 20:31:28
![](https://img.aspxhome.com/file/2023/0/80590_0s.png)
tensorflow -gpu安装方法(不用自己装cuda,cdnn)
2021-01-26 09:06:46