예제 #1
0
showtime = strftime("%Y-%m-%d %H:%M:%S", gmtime())
log.info('%s#%s', 'FECHA', showtime)

try:
    # Send data
    print('Conexion Exitosa!')
    sent = socketCliente.sendto(message, server_address)
    start_time = time.time()
    filename = './recibido/' + sys.argv[1]
    os.makedirs(os.path.dirname(filename), exist_ok=True)
    numPaquetes = 0
    bytesReceived = 0
    with open(filename, 'wb+') as formatter:
        data, address = socketCliente.recvfrom(SIZE)
        while data != bytes(''.encode()):
            formatter.write(data)
            data, address = socketCliente.recvfrom(SIZE)
            numPaquetes = numPaquetes + 1
            bytesReceived = bytesReceived + len(data)

            if data == b'Fin':
                bytesReceived = bytesReceived + len(data)
                break

        buf = formatter.read()
        print('Generando el Hash del Cliente para el archivo recibido ')
        hasher.update(buf)
        hashCliente = hasher.hexdigest()

        nomArchivoR, address = socketCliente.recvfrom(SIZE)
        log.info('%s#%s', 'NOMBRE_ARCHIVO', nomArchivoR.decode('utf-8'))
예제 #2
0
    # Send data
    print('Connected successfully')
    print('sending {!r}'.format(message))
    sent = sock.sendto(message, server_address)
    start_time = time.time()
    #data = sock.recv(1024)
    filename = './' + sys.argv[1]
    #filename = './recibido/newfile1.jpg'
    os.makedirs(os.path.dirname(filename), exist_ok=True)
    i = 0
    bytesReceived = 0
    with open(filename, 'wb+') as f:
        data, address = sock.recvfrom(SIZE)
        while data != bytes(''.encode()):
            # print(data)
            f.write(data)
            data, address = sock.recvfrom(SIZE)
            # Send data
            #print(i,data)
            i = i + 1
            #print('received {} bytes from {}'.format(len(data), address))
            bytesReceived = bytesReceived + len(data)

            if data == b'Fin':
                bytesReceived = bytesReceived + len(data)
                print('Over')
                break

        buf = f.read()
        hasher.update(buf)
        hash_cliente = hasher.hexdigest()