示例#1
0
 def do_put(self,line):
     """Puts the file into the server
         filename        : The filename should be in same folder.
         encflag         : "E" or "N", whether encryption is required or not
         opt<password>   : Password<8 Characters> for encrypting the file.
     """
     args = line.split(" ")
     if len(args)==2:
         #case put <filename> <encflag>
         filename, encflag = line.split(" ")
         if not os.path.isfile(filename):
             print ("Error: %s cannot be transferred" %filename)
             self.cmdloop()
         if encflag!='N':
             print "Wrong parameter"
             self.cmdloop()
     elif len(args)==3:
         #case put <filename> <encflag> <password>
         filename ,encflag, password = line.split(" ")
         if not os.path.isfile(filename):
             print "Error: File not found. Should be in same folder!"
             self.cmdloop()
         if encflag!="E" or len(password)!=8:
             print "Error: Wrong Flag/password"
             self.cmdloop()
     else:
         print "Error: Wrong Number of Arguments!!"
         self.cmdloop()
     fhash = Common.gen_hash(filename)
     # Hash generated send it now!
     if encflag=="E":
         Common.encrypt_file(password,filename) 
         with open(filename+".enc") as f:
             msg = f.read()
         os.remove(filename+".enc")
     else:
         with open(filename) as f:
             msg = f.read()
     Common.send_msg(self.clientsocket,"put") #Set mode to put
     Common.send_msg(self.clientsocket,msg)
     Common.send_msg(self.clientsocket,fhash)
     Common.send_msg(self.clientsocket,filename)
     #Wait for Response from Server
     print Common.recv_msg(self.clientsocket) 
示例#2
0
 def encrypt_file(self):
     """
     Encryption Wrapper from Client class.
     Encrypts the input file and creates an output file <filename.enc>
     """
     Common.encrypt_file(self.password,self.filename)