Skip to content

Instantly share code, notes, and snippets.

@hahastudio
Created November 2, 2012 11:10
Show Gist options
  • Save hahastudio/4000247 to your computer and use it in GitHub Desktop.
Save hahastudio/4000247 to your computer and use it in GitHub Desktop.
from socket import *
import os
import struct
ADDR = ('59.78.41.61',5006)#你的IP,端口随意
BUFSIZE = 1024
filename = 'sort-collection.py'#文件名,把这个文件跟要传的文件放一个目录里
FILEINFO_SIZE=struct.calcsize('128s32sI8s')
sendSock = socket(AF_INET,SOCK_STREAM)
sendSock.connect(ADDR)
fhead=struct.pack('128s11I',filename,0,0,0,0,0,0,0,0,os.stat(filename).st_size,0,0)
sendSock.send(fhead)
fp = open(filename,'rb')
while 1:
filedata = fp.read(BUFSIZE)
if not filedata: break
sendSock.send(filedata)
fp.close()
sendSock.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment