网络编程学习(9)/ FTP项目(3) ——目录切换、目录查看功能
调用功能函数以及对参数数量进行判断
客户端 server 文件夹下 FTPClient.py
def interactive(self):
"""交互指令,调用功能函数"""
if self.auth():
while True:
command = input(self.show_to_client).strip()
if not command:continue
command = command.split()
action_type = command[0]
if hasattr(self, action_type):
func = getattr(self, action_type)
func(command[1: ])
else:
print("Error: this command does not exist !")
def parameter_length_judgment(self, command,min_size=None, most_size=None, exact_size=None):
"""判断命令中参数个数是否符合规范,比如说 下载功能 至少要提供文件名的参数"""
if min_size:
if len(command) < min_size:
print("Error: supply parameter at least %s, but supply %s parameter" % (min_size,</