def Download(option): listt = sock.recv(1024) if listt != 'UPLOAD!': listt = listt.split('\n') for i in range(len(listt)): print i+1,".",listt[i] if option == "Download": no = raw_input("Enter File no to download the file : ") time.sleep(1) sock.send(no) net.downloadFile(listt[int(no)-1], sock) else: no = raw_input("Enter File no to Delete the file : ") time.sleep(1) sock.send(no) else: print "You are a new user!\nUpload some files then continue!"
def downloader(sql, client, socks, C_lib): strr = client["socket"].recv(1024) while strr != 'STOP_UPLOAD': strr = strr.split('*') filename = strr[1] # actual filename, a.txt, 3.pdf etc... m_checksum = strr[0] # file content checksum status = isFileExists(client, strr, sql, C_lib) if status: net.downloadFile(m_checksum, client["socket"]) # chane filename --> m_checksum print "File",filename,"is received and saved on Main Server as",m_checksum #names_arr = Chunk._256_kb_split(filename) chunks_manager.STORE_ALL_256_KB_001(socks, sql, m_checksum, C_lib) os.remove(m_checksum) sql._insert_(['username','filename','m_checksum'], [client["username"],strr[1],strr[0]], 'log') strr = client["socket"].recv(1024) print "Client's next query is",strr
def operations(self): msg = self.sock.recv(1024) if msg == 'WHO': self.sock.send('123123123*'+self.name) if '*' in msg: msg = msg.split('*') print "Query : ",msg if msg[0] == 'PREPARE': self.sock.send("READY") net.downloadFile(msg[1],self.sock) print "Chunk "+msg[1]+" is stored on "+self.name if msg[0] == 'MAKE': self.sock.send('READY?') sleep(1) net.uploadFile(msg[1],self.sock) #print "Chunk "+msg[1]+" is on mainserver by "+self.name if msg[0] == "DEL": print "Deletion Command received..",msg[1] if os.path.isfile(msg[1]): os.remove(msg[1]) print "Deleted",msg[1] else: print msg[1],"File is not exists!!!!!!!!!"