def close(self):
        """
        Closes the stream.
        """
        self.flush()
        try:
            if self.stream is not None:
                self.stream.flush()
                _name = self.stream.name
                self.stream.close()
                self.client.copy(_name, self.filename)
        except Exception as ex:
            print str(ex)
            pass