400多行python代码实现了一个ftp服务器

python版本 实现了比之前的xxftp更多更完善的功能 1、继续支持多用户 2、继续支持虚拟目录 3、增加支持用户根目录以及映射虚拟目录的权限设置 4、增加支持限制用户根目录或者虚拟目录的空间大小 xxftp的特点 1、开源、跨平台 2、简单、易用 3、不需要数据库 4、可扩展性超强 5、你可以免费使用xxftp假设自己的私人ftp服务器 测试地址 ftp://xiaoxia.org 匿名帐号可以使用! 匿名根目录只读,映射了一个虚拟目录,可以上传文件但不允许更改! 使用方法 跟之前用c语言写的xxftp使用方法一样: 1. create a root directory to hold the user directories. configure it in config.xml. 2. create user directories under the root directory. if you want to specify a password, create a directory named “.xxftp”, under which create a text file named “password” containing the md5 code of the password. 3. if you want to specify the welcome and goodbye message, write it in xxftp.welcome and xxftp.goodbye under the root directory. 4. configure config.xml. the structure of your ftp server root may be like: -/root -xxftp.welcome -xxftp.goodbye -user1 -.xxftp -password -… -user2 -.xxftp -password -… -anonymous源代码

代码如下:

import socket, threading, os, sys, time import hashlib, platform, stat listen_ip = “localhost” listen_port = 21 conn_list = [] root_dir = “./home” max_connections = 500 conn_timeout = 120 class ftpconnection(threading.thread): def __init__(self, fd): threading.thread.__init__(self) self.fd = fd self.running = true self.setdaemon(true) self.alive_time = time.time() self.option_utf8 = false self.identified = false self.option_pasv = true self.username = “” def process(self, cmd, arg): cmd = cmd.upper(); if self.option_utf8: arg = unicode(arg, “utf8”).encode(sys.getfilesystemencoding()) print “

Posted in 未分类

发表评论