标签:
"""
""
server.py
"""
服务端
"""
import socket
import os
s=socket.socket()
s.bind((‘127.0.0.1‘,8888,))
s.listen(5)
while True:
c,addr=s.accept()
c.sendall(bytes("上传FTP",encoding="utf-8"));
file_size=str(c.recv(1024),encoding="utf-8");
print(file_size)
total_size=int(file_size);
hots=0
print(file_size);
c.sendall(bytes("洗",encoding="utf-8"));
f=open(‘d:/jPG/2.jpg‘,‘wb‘)
while True:
if hots==total_size:
break;
data=c.recv(1024)
f.write(data)
hots+=len(data);
f.close()
"客户端"
c.py
"""
FTP 客户端
"""
import socket
import json,os
s=socket.socket()
s.connect(("127.0.0.1",8888,))
rest_bytes=s.recv(1024)
res_str=str(rest_bytes,encoding="UTF-8");
print(res_str)
file_size=os.stat(‘d:/jPG/1.jpg‘).st_size
s.sendall(bytes(str(file_size),encoding="utf-8"));
s.recv(1024)
#发送文件
with open(‘D:/jPG/1.jpg‘,‘rb‘) as f:
for line in f:
s.sendall(line);
f.close();
c.py
标签:
原文地址:http://www.cnblogs.com/wxc1/p/5658669.html