def _wrap_close_transport(channel, transport):
    """
    Wrap a Channel or SFTPFile object so its close() method also closes
    the underlying Transport.
    """

    def close():
        """ Close this object and the underlying Transport """
        channel._orig_close()  # pylint: disable=protected-access
        transport.close()

    if not hasattr(channel, '_orig_close'):
        setattr(channel, '_orig_close', channel.close)
        setattr(channel, 'close', close)

    return channel