<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def to_dir_path_url(url_info: URLInfo) -> str:
    '''Return URL string with the path replaced with directory only.'''
    dir_name = posixpath.dirname(url_info.path)

    if not dir_name.endswith('/'):
        url_template = 'ftp://{}{}/'
    else:
        url_template = 'ftp://{}{}'

    return url_template.format(url_info.hostname_with_port, dir_name)