import optparse
#class FtpClient(object): #自定义类可以自己修改
'''ftp客户端'''
#def __init__(self):
parser = optparse.OptionParser()
parser.add_option("-s","--server",dest = "server",help="ftp server ip_addr")
parser.add_option("-P","--port",type = "int",dest="port",help="ftp server port")
parser.add_option("-u","--username",dest="username",help="username info")
parser.add_option("-p","--password",dest="password",help="password info")
self.options , self.args = parser.parse_args()
print(self.options,self.args)
#optparser 模块 提取IP,端口,用户名,密码参数模板 -s 后面跟IP,大写 -P 后面是端口. -u 用户名 -p密码
#演示结果
#C:UsersAdministratorPycharmProjectsuntitled1untitled1网络编程LuffyFTPclient>python luffy_client.py -s 192.168.1.22 -P 9000 -u andyzhang -p abc
#{'server': '192.168.1.22', 'port': 9000, 'username': 'andyzhang', 'password': 'abc'} []
def argv_verification(self):
'''检查参数合法性'''
if not self.options.server or not self.options.port: #获取optparse 模块的字典方法。有属必 .server .port
exit('Error:must supply server and port parameters')