day22 ftp传输作业未完成

class MyFtpTcpSever:

        POST = 8686
        flie_Path =r'W_26/day3(scoket拓展)/downlode_file/01 python  fullstack 开班介绍 part1.mp4'
        downlode_path = r'W_26/day3(scoket拓展)/文件传输'
        socket_family = AF_INET
        socket_type = SOCK_STREAM
        coding = 'utf-8'
        request_queue_size = 5
        allow_reuse_address = False
        max_packet_size = 8192

        def __init__(self, server_address,bind_and_activate=True):
            """Initializer  May be extended, do not override"""
            self.server_address =server_address
            self.server_socket = socket(self.socket_family,self.socket_type)
            if bind_and_activate:
                try:
                    self.server_bine()
                    self.listen()
                except:
                    print('connect false')
                print('copnnect successful')


        def server_bine(self):
            '''套接字绑定ip地址'''
            self.server_socket.bind(self.server_address)
            self.server_address = self.server_socket.getsockname()



        def sever_listen(self):
            """激活套接字监听"""
            self.server_socket.listen(self.request_queue_size)
            return


        def sever_close(self):
            '''回收资源'''
            self.server_socket.close()

        def sever_requset(self):
            '''接收请求'''
            return self.server_socket.accept()


        def send_hand_len(self,hand_data):
            """第一次 发送标头长度标头"""
            hand = struct.pack('i',len(hand_data))
            self.server_socket.send(hand)

        def send_hand(self,operat):
            self.file_name = os.path.basename(self.flie_Path)
            self.file_size = os.path.getsize(self.flie_Path)
            hand={
                'file name' : self.file_name,
                'file size' : self.file_size,
                'cmd' : operat
            }

        def pras_cmd(self,cmd = b"sadd"):
            """解析命令行"""
            args = cmd.decode('utf-8').split()
            return args

        def sever_downlode(self,args):
            cmd = args[0]
            file_name = args[1]
            file_path = os.path.join(self.downlode_path,file_name)
            with open(file_path,'rb') as f:
                for line in f:
                    self.server_socket.send(line)

        def run(self):
            while True:
                pass

 

posted @ 2020-04-12 19:00  不忘初心--方得始终  阅读(147)  评论(0编辑  收藏  举报