Python版本
实现了比之前的xxftp更多更完善的功能
1、继续支持多用户
2、继续支持虚拟目录
3、增加支持用户根目录以及映射虚拟目录的权限设置
4、增加支持限制用户根目录或者虚拟目录的空间大小
xxftp的特点
1、开源、跨平台
2、简单、易用
3、不需要数据库
4、可扩展性超强
5、你可以免费使用xxftp假设自己的私人FTP服务器
测试地址
ftp://xiaoxia.org
匿名帐号可以使用!
匿名根目录只读,映射了一个虚拟目录,可以上传文件但不允许更改!
使用方法
跟之前用C语言写的xxftp使用方法一样:
- Create a root directory to hold the user directories.
Configure it in config.xml. - 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. - If you want to specify the welcome and goodbye message, write it in
xxftp.welcome and xxftp.goodbye under the root directory. - 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 “<<”, cmd, arg, self.fd
Ftp Command
if cmd == “BYE” or cmd == “QUIT”:
if os.path.exists(root_dir + “/xxftp.goodbye”):
self.message(221, open(root_dir + “/xxftp.goodbye”).read())
else:
self.message(221, “Bye!”)
self.running = False
return
elif cmd == “USER”:
Set Anonymous User
if arg == “”: arg = “anonymous”
for c in arg:
if not c.isalpha() and not c.isdigit() and c!="_":
self.message(530, “Incorrect username.”)
return
self.username = arg
self.home_dir = root_dir + “/” + self.username
self.curr_dir = “/”
self.curr_dir, self.full_path, permission, self.vdir_list, \
limit_size, is_virtual = self.parse_path("/")
if not os.path.isdir(self.home_dir):
self.message(530, “User " + self.username + " not exists.”)
return
self.pass_path = self.home_dir + “/.xxftp/password”
if os.path.isfile(self.pass_path):
self.message(331, "Password required for " + self.username)
else:
self.message(230, “Identified!”)
self.identified = True
return
elif cmd == “PASS”:
if open(self.pass_path).