在windows上建立fitp服务器
在linux环境上weget ftp://user:password@ip:port/file_path
windows上搭建ftp服务器代码如下:
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler, ThrottledDTPHandler
from pyftpdlib.servers import FTPServer
from conf import settings
import logging
def get_user(userfile):
#定义一个用户列表
user_list = []
with open(userfile) as f:
for line in f:
if not line.startswith('#') and line:
if len(line.split()) == 4:
user_list.append(line.split())
else:
print("user.conf配置错误")
print(user_list)
return user_list
def ftp_server():
#实例化虚拟用户,这是FTP验证首要条件
authorizer = DummyAuthorizer()
authorizer.add_user('usera', '12345', '/ftp/acct_info', perm='elradfmw')
#添加匿名用户 只需要路径
if settings.enable_anonymous == 'on':
authorizer.add_anonymous(settings.anonymous_path)
#下载上传速度设置
dtp_handler = ThrottledDTPHandler
dtp_handler.read_limit = settings.max_download
dtp_handler.write_limit = settings.max_upload
#初始化ftp句柄
handler = FTPHandler
handler.authorizer = authorizer
#日志记录
if settings.enable_logging == 'on':
logging.basicConfig(filename=settings.loging_name, level=logging.INFO)
#欢迎信息
handler.banner = settings.welcome_msg
#添加被动端口范围
handler.passive_ports = range(settings.passive_ports[0], settings.passive_ports[1])
#监听ip 和 端口
server = FTPServer((settings.ip, settings.port), handler)
#最大连接数
server.max_cons = settings.max_cons
server.max_cons_per_ip = settings.max_per_ip
#开始服务
print('开始服务')
server.serve_forever()
if __name__ == "__main__":
ftp_server()
网友评论