def remote_to_string(remote):
    """Return a string matching the input remote dictionary

    The input should be in the following form:
    {'host': 'HOST', 'username': 'USERNAME', 'password': 'PASSWORD'}
    Note that the PASSWORD item is optional.

    The output will be in the following form:
    USERNAME:PASSWORD@HOST
    The ':PASSWORD' part is optional.

    Return None if the input is not valid.
    """
    if 'host' not in remote or 'username' not in remote:
        return None
    if 'password' in remote:
        return '%s:%s@%s' % (remote['username'], remote['password'], remote
            ['host'])
    else:
        return '%s@%s' % (remote['username'], remote['host'])
