sock_client_ftp.py
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 = 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的主要内容,如果未能解决你的问题,请参考以下文章