代码拉取完成,页面将自动刷新
#!/usr/bin/python
#coding: utf-8
import socket
import time
ip = '127.0.0.1'
port = 60000
s = socket.socket()
def recvfile(filename):
print 'server ready, now clinet recv file--->'
f = open(filename,'wb')
while True:
data = s.recv(4096)
if data == 'EOF':
print 'recv file success!'
break
f.write(data)
f.close()
def sendfile(filename):
print 'server ready ,now clinet sending file--->'
f = open(filename,'rb')
while True:
data = f.read(4096)
if not data:
break
s.sendall(data)
f.close()
time.sleep(1)
s.sendall('EOF')
print 'send file success!'
def confirm(s,clinet_command):
s.send(clinet_command)
data = s.recv(4096)
if data =='read':
return True
try:
s.connect((ip,port))
while 1:
clinet_command = raw_input('>>')
if not clinet_command:
continue
action,filename = clinet_command.split()
if action == 'put':
path_filename = filename.split('/')[-1]
if confirm(s,clinet_command):
sendfile(path_filename)
else:
print 'server get error!'
elif action == 'get':
if confirm(s,clinet_command):
recvfile(filename)
else:
print 'server get error'
else:
print 'command error!'
except socket.error,e:
print 'get error as',e
finally:
s.close()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。