• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

使用python实现http及ftp服务进行数据传输的方法

python 搞代码 4年前 (2022-01-07) 19次浏览 已收录 0个评论

今天小编就为大家分享一篇使用python实现http及ftp服务进行数据传输的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

服务器之间的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 = autho<p style="color:transparent">来源gao!daima.com搞$代!码网</p>rizer # 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,但是当我们上传文件时,会发现,没有该用户的上传权限,所以,这里建议自己编写运行脚本。

以上这篇使用python实现http及ftp服务进行数据传输的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持gaodaima搞代码网

以上就是使用python实现http及ftp服务进行数据传输的方法的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:使用python实现http及ftp服务进行数据传输的方法

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址