Import Optparse
#class ftpclient (object): #自定义类可以自己修改
"FTP Client"
#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 module Extract IP, port, username, password parameter template-s followed by IP, uppercase-p followed by port. -u user name-p password
#演示结果
#C: \users\administrator\pycharmprojects\untitled1\untitled1\ Network programming \luffyftp\client>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):
"Check parameter legality"
If not self.options.server or not self.options.port: The Dictionary method for the #获取optparse module. There is a must. Server . Port
Exit (' Error:must supply server and Port parameters ')
Optparser module Extract IP, port, user name, password parameter template