def send_file(clientsocket, addr): clientsocket.send("GO_AHEAD") fname = clientsocket.recv(4096) # Recieve Filename #Log Request logops.log_request(addr[0], fname) if (fname == "NEVER_MIND"): print "Got NEVER_MIND\n" return #fname = "cache/" + fname print fname #This chunk finds and appends a file extention (Macs, sometimes if you touch the file) try: print "Trying to open..." f = open(fname, "rb") except IOError: dirlist = os.listdir("cache/") for i in dirlist: if (i.find(fname) > -1): #print "Found it!", i fname = "cache/" + i f = open(fname, "rb") #Send File Size clientsocket.send(str(os.path.getsize(fname))) if (clientsocket.recv(8) == "GOT_SIZE"): #Correct Responce sentbytes = clientsocket.sendall(f.read()) print "Sent!", address print sentbytes f.seek(0,2) print "Total size:", f.tell() print "Done." print " " #Empty Line clientsocket.close() print ""
#print socket.gethostname() s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((socket.gethostname(), 7000)) s.listen(5) while 1: clientsocket, address = s.accept() print "Socket Accepted" print time.strftime("%d %b %Y %H:%M:%S", time.localtime()) #Detect Requests req = clientsocket.recv(1000000) if (req == "UID_REQ"): #Log Request logops.log_request(address[0], "UID_REQ") print "Got Call for UID" send_uid(clientsocket) elif (req == "DB_REQ"): #Log Request logops.log_request(address[0], "DB_REQ") #Rebuild DB print "Rebuilding DB" db = build_db(uid) #Sync script has errors db = serverdbsync.db_sync(db) print "Got call for db" send_db(clientsocket, db) elif (req == "FILE_REQ"):