国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

400多行Python代碼實現了一個FTP服務器

2020-02-23 04:47:06
字體:
來源:轉載
供稿:網友
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):
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长泰县| 榕江县| 长治市| 兴城市| 巴林左旗| 钦州市| 兴义市| 克什克腾旗| 汉阴县| 额敏县| 锦州市| 巴彦县| 汝阳县| 沈阳市| 陈巴尔虎旗| 行唐县| 临潭县| 南充市| 文成县| 安徽省| 松溪县| 象州县| 固原市| 鸡西市| 江都市| 苍溪县| 昌江| 绥中县| 天津市| 封丘县| 象山县| 壶关县| 襄樊市| 中阳县| 灯塔市| 象山县| 包头市| 普格县| 德化县| 齐齐哈尔市| 栾川县|