Created
November 2, 2012 11:10
-
-
Save hahastudio/4000247 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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