static int ftp_auth(FTPContext *s)
{
    const char *user = NULL, *pass = NULL;
    char *end = NULL, buf[CONTROL_BUFFER_SIZE], credencials[CREDENTIALS_BUFFER_SIZE];
    int err;

    /* Authentication may be repeated, original string has to be saved */
    av_strlcpy(credencials, s->credencials, sizeof(credencials));

    user = av_strtok(credencials, ":", &end);
    pass = av_strtok(end, ":", &end);

    if (!user) {
        user = "anonymous";
        pass = s->anonymous_password ? s->anonymous_password : "nopassword";
    }

    snprintf(buf, sizeof(buf), "USER %s\r\n", user);
    if ((err = ffurl_write(s->conn_control, buf, strlen(buf))) < 0)
        return err;
    ftp_status(s, &err, NULL, NULL, NULL, -1);
    if (err == 3) {
        if (pass) {
            snprintf(buf, sizeof(buf), "PASS %s\r\n", pass);
            if ((err = ffurl_write(s->conn_control, buf, strlen(buf))) < 0)
                return err;
            ftp_status(s, &err, NULL, NULL, NULL, -1);
        } else
            return AVERROR(EACCES);
    }
    if (err != 2) {
        return AVERROR(EACCES);
    }

    return 0;
}