Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import os
- x = 0
- s = socket.socket()
- host = socket.gethostname()
- port = 80
- s.bind(( host , port))
- s.listen(5)
- name = "file-name="
- iname = "image-name="
- while True:
- c, addr = s.accept() # Establish connection with client.
- print 'Got connection from', addr
- print "Receiving..."
- l=c.recv(1024)
- if ("favicon.ico" in l):
- continue
- if ("GET /" in l) and (" HTTP/1.1" in l):
- print (l)
- index = l.index(iname)
- index = index+len(iname)
- index2 = l.index("HTTP")
- file_name=l[index:index2]
- print(file_name)
- isf=os.path.isfile("upload/"+file_name)
- if isf:
- f=open("upload/"+file_name,'rb')
- l=f.read()
- while (l):
- c.send(l)
- l = f.read(1024)
- print(file_name)
- c.send(file_name)
- c.close()
- f.close()
- else:
- f=open("upload\e4.html",'rb')
- l=f.read()
- while (l):
- c.send(l)
- l = f.read(1024)
- c.close()
- f.close()
- else:
- index=l.index(name)
- index=index+len(name)
- index2=l.index("HTTP")
- file_name=l[index:index2]
- print(file_name)
- f=open('upload/'+"("+str(x)+")"+file_name, 'wb')
- while l:
- l=c.recv(1024)
- f.write(l)
- f.close()
- print "Done Receiving"
- c.send('Thank you for connecting')
- c.close()
- x+=1
- print "server is shutting down"
- s.shutdown()
Add Comment
Please, Sign In to add comment