python 上传下载文件
server.py #!/usr/bin/env python
# -*- coding:utf- -*-
import SocketServer
import os class MySocketServer(SocketServer.BaseRequestHandler): def handle(self):
filename_dir = '/home/feng/feng'
conn = self.request
data = conn.recv()
filename,filename_size = data.strip().split('|') print filename,filename_size recv_size = file_dir=os.path.join(filename_dir,filename) f = open(file_dir,'w+') while True:
if int(filename_size) != recv_size :
data = conn.recv()
recv_size += len(data)
print int(filename_size),recv_size
f.write(data)
else:
break
# else:
# data = conn.recv(int(filename_size) - recv_size)
# print int(filename_size) - recv_size
# break
print 'upload successed.......' if __name__ == '__main__':
ip_port = ('127.0.0.1',)
server = SocketServer.ThreadingTCPServer(ip_port,MySocketServer)
server.serve_forever() =======================================
client.py
#!/usr/bin/env python
# -*- coding:utf- -*-
import socket
import os client = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
ip_port = ('127.0.0.1',)
client.connect(ip_port) while True:
filepath = raw_input('请输入方法和上传路径:/root/1.txt: ')
filename_size = os.stat(filepath).st_size
filename = os.path.basename(filepath) print '#####################'
print filepath,filename_size
print '#####################' client.send(filename + '|' + str(filename_size))
send_size = f = open(filepath,'r') Flag = True
while Flag:
if filename_size != send_size:
data = f.read()
send_size += len(data)
client.send(data)
else:
Flag=False
f.close()
client.close()
python 上传下载文件的更多相关文章
- windows上python上传下载文件到linux服务器指定路径【转】
从windows上传文件到linux,目录下的文件夹自动创建 #!/usr/bin/env python # coding: utf-8 import paramiko import datetime ...
- python实现socket上传下载文件-进度条显示
在python的socket编程中,可以实现上传下载文件,并且在下载的时候,显示进度条,具体的流程如下图所示: 1. 服务器端代码如下: [root@python 519]# cat server.p ...
- 初级版python登录验证,上传下载文件加MD5文件校验
服务器端程序 import socket import json import struct import hashlib import os def md5_code(usr, pwd): ret ...
- rz和sz上传下载文件工具lrzsz
######################### rz和sz上传下载文件工具lrzsz ####################################################### ...
- linux上很方便的上传下载文件工具rz和sz
linux上很方便的上传下载文件工具rz和sz(本文适合linux入门的朋友) ##########################################################&l ...
- shell通过ftp实现上传/下载文件
直接代码,shell文件名为testFtptool.sh: #!/bin/bash ########################################################## ...
- SFTP远程连接服务器上传下载文件-qt4.8.0-vs2010编译器-项目实例
本项目仅测试远程连接服务器,支持上传,下载文件,更多功能开发请看API自行开发. 环境:win7系统,Qt4.8.0版本,vs2010编译器 qt4.8.0-vs2010编译器项目实例下载地址:CSD ...
- linux下常用FTP命令 上传下载文件【转】
1. 连接ftp服务器 格式:ftp [hostname| ip-address]a)在linux命令行下输入: ftp 192.168.1.1 b)服务器询问你用户名和密码,分别输入用户名和相应密码 ...
- C#实现http协议支持上传下载文件的GET、POST请求
C#实现http协议支持上传下载文件的GET.POST请求using System; using System.Collections.Generic; using System.Text; usin ...
随机推荐
- 新浪SAEStorage图片上传的demo和说明
<?php if(isset($_POST[up])){ $s2 =new SaeStorage();//实例化 $name =$_FILES['myfile']['name'];//上传到服务 ...
- Redis在windows环境下的部署
一.下载 官网地址:http://redis.io/download Git地址:https://github.com/MSOpenTech/redis 注:官方无windows版本,需要window ...
- UIButton的遍历
for (id obj in self.view.subviews) { if ([obj isKindOfClass:[UIButton class]]) { ...
- Windows与Linux/Mac系统时间不一致的解决方法
Windows与Linux/Mac系统时间不一致的解决方法 分类: linux2012-02-12 14:25 1691人阅读 评论(1) 收藏 举报 windowsubuntusystemlinux ...
- Configuration.ConfigurationSettings.AppSettings已过时
1.在项目中引用System.Configuration.dll,在需要的页面加上using System.Configuration; 2.把ConfigurationSettings.AppSet ...
- 转一个 C#基础类库
转自:http://www.cnblogs.com/sufei/archive/2012/12/07/2807170.html http://www.sufeinet.com/thread-655-1 ...
- angularjs select 循环中出现第一个 option 为空格问题
当select 的ng-module 为空时, select显示空白行. 解决:指定ng-module的默认值.
- window平台安装MongoDB
官网:www.mongodb.org 安装-->设置环境变量-->启动 1.下载: 根据系统下载 32 位或 64 位的 .msi 文件,下载后双击该文件,按提示安装即可, 2.设置安装目 ...
- A Framework for Programme Management
In business today organisations manage multiple projects concurrently with shared or overlapping res ...
- sublime text2 操作及插件
sublime text2 1. 文件快速导航: 这是sublime上面很好用的功能之一,ctrl+p可以调出窗口,菜单上的解释是gotoanythings ,确实如其所言,调出窗口后,直接输入关键字 ...