首页 > 代码库 > sock_client_ftp.py
sock_client_ftp.py
import socket,hashlib client = socket.socket() client.connect(("localhost", 6971)) ##开始连接 (ServerIP,ServerPort) while True: cmd = input("Please input the message>>").strip() print(cmd) if len(cmd) == 0:continue if cmd.startswith("get"): client.send(cmd.encode("utf-8")) server_response = client.recv(1024) print("server resonse:",server_response) client.send(b"ready yo recv file") file_total_size = int(server_response.decode()) received_size = 0 filename = cmd.split()[1] f = open(filename + ".new","wb") m = hashlib.md5() while received_size < file_total_size: if file_total_size - received_size > 1024: size = 1024 else: size = file_total_size - received_size print("lase recv:",size) data = client.recv(size) # data = http://www.mamicode.com/client.recv(1024) received_size +=len(data) m.update(data) f.write(data) else: new_file_md5 = m.hexdigest() f.close() server_file_md5 = client.recv(1024) print("server file md5:",server_file_md5) print("clinet file md5:",new_file_md5) client.close()
sock_client_ftp.py
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。