首页 > 代码库 > FTP
FTP
class Ftp_server(socketserver.BaseRequestHandler): code="utf-8" def handle(self): while True: recv_head=self.request.recv(4) #收报头的长度 recv_data_len=struct.unpack("i",recv_head) print(recv_data_len) recv_head_data=self.request.recv(recv_data_len[0]) #收报头信息 print(recv_head_data) data_size=json.loads(recv_head_data)["data_size"] #--------------------------------------------------------------------------------------------- recv_size=0 with open("s",‘wb‘) as f: while recv_size < data_size: #开写数据 data=http://www.mamicode.com/self.request.recv(1024) f.write(data) recv_size+=len(data) self.request.send("传输完成".encode("utf-8")) def put(self): print("alex草你妈") if __name__ == ‘__main__‘: obj=socketserver.ThreadingTCPServer(("127.0.0.1",8080),Ftp_server) obj.serve_forever()
class Client(): def __init__(self,Addr_server): self.addr_server=Addr_server self.socket = socket.socket() self.client_connect() def client_connect(self): self.socket.connect(self.addr_server) def run(self): while True: name_inpu = input("请输入用户名: ") flie_inpu = input("请输入要传输的文件路径: ").strip() filesize = os.path.getsize(flie_inpu) dic = {"name": name_inpu, "file": flie_inpu, "data_size": filesize} bytes_dic=json.dumps(dic).encode("utf-8") len_dic = len(bytes_dic) struct_len = struct.pack("i", len_dic) self.socket.send(struct_len) self.socket.send(bytes_dic) with open(‘c‘,‘rb‘) as f: for i in f: self.socket.send(i) print(self.socket.recv(1023).decode("utf-8")) c=Client(("127.0.0.1",8080)) c.run()
FTP
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。