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 "<<", 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):