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;
    const int user_codes[] = {331, 230, 500, 530, 0}; /* 500, 530 are incorrect codes */
    const int pass_codes[] = {230, 503, 530, 0}; /* 503, 530 are incorrect codes */

    /* 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);
    err = ftp_send_command(s, buf, user_codes, NULL);
    if (err == 331) {
        if (pass) {
            snprintf(buf, sizeof(buf), "PASS %s\r\n", pass);
            err = ftp_send_command(s, buf, pass_codes, NULL);
        } else
            return AVERROR(EACCES);
    }
    if (err != 230)
        return AVERROR(EACCES);

    return 0;
}