'When the connection is lost, I close the file.
@param reason: The reason why the connection was lost.
@type reason: L{Failure}'

def connectionLost(self, reason):

    self.connected = 0
    logmsg = ('%s    closed.' % (self,))
    if (self.fileSize > 0):
        logmsg = ('%s        %d/%d    bytes    received' % (logmsg, self.bytesReceived, self.fileSize))
        if (self.bytesReceived == self.fileSize):
            pass
        elif (self.bytesReceived < self.fileSize):
            logmsg = ('%s    (Warning:    %d    bytes    short)' % (logmsg, (self.fileSize - self.bytesReceived)))
        else:
            logmsg = ('%s    (file    larger    than    expected)' % (logmsg,))
    else:
        logmsg = ('%s        %d    bytes    received' % (logmsg, self.bytesReceived))
    if hasattr(self, 'file'):
        logmsg = ('%s    and    written    to    %s.\n' % (logmsg, self.file.name))
        if hasattr(self.file, 'close'):
            self.file.close()
