python3利用pyftpdlib模块启动ftp服务

环境:

  • win7 旗舰版
  • python @3.6.1
  • pyftpdlib @1.5.4

python客户端上官网下载:python 安装的时候勾上pip还有add path 环境变量。

pyftpdlib模块可用pip安装:

pip(3) install pyftpdlib

pyftpdlibGithub项目链接:https://github.com/giampaolo/pyftpdlib/

下面给出一个基础的例子:

开启一个ftp服务器,用户user,密码12345,禁止匿名登录

import os

from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer

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='elradfmwMT')
    #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 = ('127.0.0.1', 2121)
    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()

要开启请执行:

python server.py

看到如下界面说明开启成功。

bdc70b0aly1fs30spqv4bj20it0bejse.jpg

资源管理器打开:

ftp://127.0.0.1:2121

bdc70b0aly1fs30vb9079j20p70j5q5m.jpg

bdc70b0aly1fs30vypp13j20gp0e4wef.jpg

成功访问。更多内容可参考官方文档

转载于:https://www.cnblogs.com/ronething/p/9163360.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值