ftplib教程linux,Linux下pyftplib简单的脚本

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('admin', '12345', '/root',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 = "Simple FTPServer."

# 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 = ('192.168.3.177', 21)

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()

关于脚本的一些说明:

建立一个authorizer = DummyAuthorizer() 对象的实例

利用.add_user方法添加一个用户 authorizer.add_user('admin', '12345', '/root',perm='elradfmwM')

关于建立用户的参数的说明:

admin 用户名

'12345' 密码

/root 用户的根目录

perm='elradfmwM' 设置用户的权限

关于perm='elradfmwM' 参数介绍:

Read permissions:

- "e" = change directory (CWD command)

- "l" = list files (LIST, NLST, STAT, MLSD, MLST, SIZE, MDTM commands)

- "r" = retrieve file from the server (RETR command)

Write permissions:

- "a" = append data to an existing file (APPE command)

- "d" = delete file or directory (DELE, RMD commands)

- "f" = rename file or directory (RNFR, RNTO commands)

- "m" = create directory (MKD command)

- "w" = store a file to the server (STOR, STOU commands)

- "M" = change file mode (SITE CHMOD command)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值