解决办法:把buffer改小

server.py

 #实现一个大文件的上传或下载
#配置文件 ip地址 端口号
import json
import socket
import struct
sk = socket.socket()
#起服务
sk.bind(('127.0.0.1', 8090))
sk.listen()
10 buffer = 1024
conn,addr = sk.accept()
#接收
head_len = conn.recv(4)
head_len = struct.unpack('i', head_len)[0]
json_head = conn.recv(head_len).decode('utf-8')
head = json.loads(json_head)
filesize = head['filesize']
with open(head['filename'], 'wb') as f:
while filesize:
print(filesize)
if filesize >= buffer:
content = conn.recv(buffer)
f.write(content)
filesize -= buffer
else:
content = conn.recv(filesize)
f.write(content)
break
conn.close()
sk.close()

client.py

 #发送端
import os
import json
import struct
import socket
sk = socket.socket()
sk.connect(('127.0.0.1', 8090))
8 buffer = 1024 #发送文件
head = {'filepath':r'C:\Users\Administrator\Desktop',
'filename':r'test.txt',
'filesize':None}
fie_path = os.path.join(head['filepath'],head['filename'])
filesize = os.path.getsize(os.path.join(head['filepath'],head['filename'])) head['filesize'] = filesize
json_head = json.dumps(head) #字典转成了字符串
bytes_head = json_head.encode('utf-8') #字符串转bytes
print(json_head)
print(bytes_head)
#计算head的长度
head_len = len(bytes_head) #报头的长度
pack_len = struct.pack('i', head_len)
sk.send(pack_len) #先发报头的长度
sk.send(bytes_head) #再发送bytes类型的报头
with open(fie_path, 'rb') as f:
while filesize:
print(filesize)
if filesize >= buffer:
content = f.read(buffer) #每次读出来的内容
sk.send(content)
filesize -= buffer
else:
content = f.read(filesize)
sk.send(content)
break
sk.close()

Python--day32--ftp文件传输报错的原因的更多相关文章

  1. Python读取CSV文件,报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0xa7 in position 727: illegal multibyte sequence

    Python读取CSV文件,报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0xa7 in position 727: illegal mul ...

  2. python引用py文件中文报错

    文件 a.py 中引用文件 b.py 如果文件b.py中包含中文,会报错. 文件hello.py中代码如下: def say_nihao(): print "你好" 文件main. ...

  3. Python实现终端FTP文件传输

    实现终端FTP文件传输 代码结构: .├── client.py├── readme.txt└── server.py 运行截图: readme.txt tftp文件服务器 项目功能: * 客户端有简 ...

  4. Python 基于Python实现Ftp文件上传,下载

    基于Python实现Ftp文件上传,下载   by:授客 QQ:1033553122 测试环境: Ftp客户端:Windows平台 Ftp服务器:Linux平台 Python版本:Python 2.7 ...

  5. Python numpy 安装以及处理报错 is not a supported wheel on this platform

    1.    安装 1)去这里搜索https://pypi.org/ 2)搜索框输入numpy 3)一般第一个就是搜索到的 4)点进去 5) Download files 点进去,找自己的版本 6)nu ...

  6. python安装包的时候报错

    python安装包的时候报错 今天兴致勃勃的安装了一个paramiko包,过程很顺利,但是到结尾的时候报错,这就让人不爽了. 所以呢,需要安装一个名为python-dev的软件包. 该软件包包括头文件 ...

  7. FTP 文件传输服务

    昨晚心血来潮,尝试用python写了一个ftp文件传输服务,可以接收指令,从远程ftp服务器同步指定目录数据,最后没用上,开源出来. https://github.com/jadepeng/ftp_t ...

  8. 【svn】在提交文件是报错:previous operation has not finished;run 'cleanup' if it was interrupted

    1.svn在提交文件是报错:previous operation has not finished;run 'cleanup' if it was interrupted2.原因,工作队列被占用,只需 ...

  9. R.java 文件内报错:Underscores can only be used with source level 1.7 or greater。

    R.java 文件内报错:Underscores can only be used with source level 1.7 or greater 网上查找后得知是Android工程图片资源命名的问 ...

随机推荐

  1. 2018-5-22-SublimeText-粘贴图片保存到本地

    title author date CreateTime categories SublimeText 粘贴图片保存到本地 lindexi 2018-05-22 15:15:26 +0800 2018 ...

  2. 非接触型手掌静脉识别 PalmSecure™

    静脉识别,使用近红外线读取静脉模式,与存储的静脉模式进行比较,进行本人识别的识别技术.富士通的PalmSecure™,利用该技术,由离开识别装置的位置,使用近红外线拍摄,与预先存储的静脉模式进行比较从 ...

  3. django查看数据库

    #views import pymysql def get_date(request): conn = pymysql.connect( host='localhost', port=3306, us ...

  4. Directx11教程39 纹理映射(9)

    原文:Directx11教程39 纹理映射(9)     在myTutorialD3D11_32中,我们在PlaneModelClass中增加一个纹理TextureClass* m_Texture;读 ...

  5. 【水滴石穿】AB-B-Clone

    地址: 源码 运行效果 无别的效果,代码如下 //index.js /** * @format * @lint-ignore-every XPLATJSCOPYRIGHT1 */ import {Ap ...

  6. More Effective C++: 01基础议题

    01:仔细区别 pointers 和 references 1:没有所谓的null reference,但是可以将 pointer 设为null.由于 reference 一定得代表某个对象,C++ ...

  7. redis 如何查看版本

    ./redis-cli -h 127.0.0.1 info | grep 'redis_version' redis-server -v

  8. OpenJudge_1477:Box of Bricks

    描述 Little Bob likes playing with his box of bricks. He puts the bricks one upon another and builds s ...

  9. .Net Core,VUE,VS Code,Sql Sugar,Element UI学习笔记

    1..Net Core的目的是跨平台,并主要目标是作为服务端开发使用.从3.0开始,引入了Winfrom和WPF. 2..Net Core可以引用.Net Framework生成的dll和exe,不限 ...

  10. 一 linux安装python3

    参考 https://www.cnblogs.com/pyyu/p/7402145.html?tdsourcetag=s_pcqq_aiomsg 1 下载 网址:https://www.python. ...