<commit_before>/***************************************************************************
 *                                  _   _ ____  _
 *  Project                     ___| | | |  _ \| |
 *                             / __| | | | |_) | |
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 * Copyright (C) 1998 - 2020, <NAME>, <<EMAIL>>, et al.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution. The terms
 * are also available at https://curl.se/docs/copyright.html.
 *
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
 * copies of the Software, and permit persons to whom the Software is
 * furnished to do so, under the terms of the COPYING file.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ***************************************************************************/
#include <stdio.h>

#include <curl/curl.h>

/* <DESC>
 * Get a single file from an FTP server.
 * </DESC>
 */

struct FtpFile
{
    const char* filename;
    FILE* stream;
};

static size_t my_fwrite(void* buffer, size_t size, size_t nmemb, void* stream)
{
    struct FtpFile* out = (struct FtpFile*)stream;
    if (!out->stream)
    {
        /* open file for writing */
        out->stream = fopen(out->filename, "wb");
        if (!out->stream)
            return -1; /* failure, can't open file to write */
    }
    return fwrite(buffer, size, nmemb, out->stream);
}

int main(void)
{
    CURL* curl;
    CURLcode res;
    struct FtpFile ftpfile = {
        "curl.tar.gz", /* name to store the file as if successful */
        NULL};

    curl_global_init(CURL_GLOBAL_DEFAULT);

    curl = curl_easy_init();
    if (curl)
    {
        /*
     * You better replace the URL with one that works!
     */
        curl_easy_setopt(curl, CURLOPT_URL,
                         "ftp://192.168.65.142/gghc.mp4");
        /* Define our callback to get called when there's data to be written */
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
        /* Set a pointer to our struct to pass to the callback */
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);

        /* Switch on full protocol/debug output */
        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
        curl_easy_setopt(curl, CURLOPT_USERPWD, "<PASSWORD>");
        res = curl_easy_perform(curl);

        /* always cleanup */
        curl_easy_cleanup(curl);

        if (CURLE_OK != res)
        {
            /* we failed */
            fprintf(stderr, "curl told us %d\n", res);
        }
    }

    if (ftpfile.stream)
        fclose(ftpfile.stream); /* close the local file */

    curl_global_cleanup();

    return 0;
}<commit_msg>linux cpp curl opt test 0<commit_after>/***************************************************************************
 *                                  _   _ ____  _
 *  Project                     ___| | | |  _ \| |
 *                             / __| | | | |_) | |
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 * Copyright (C) 1998 - 2020, <NAME>, <<EMAIL>>, et al.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution. The terms
 * are also available at https://curl.se/docs/copyright.html.
 *
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
 * copies of the Software, and permit persons to whom the Software is
 * furnished to do so, under the terms of the COPYING file.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ***************************************************************************/
#include <stdio.h>

#include <curl/curl.h>
#include <math.h>
/* <DESC>
 * Get a single file from an FTP server.
 * </DESC>
 */

struct FtpFile
{
    const char* filename;
    FILE* stream;
};

static size_t my_fwrite(void* buffer, size_t size, size_t nmemb, void* stream)
{
    struct FtpFile* out = (struct FtpFile*)stream;
    if (!out->stream)
    {
        /* open file for writing */
        out->stream = fopen(out->filename, "wb");
        if (!out->stream)
            return -1; /* failure, can't open file to write */
    }
    return fwrite(buffer, size, nmemb, out->stream);
}
#if LIBCURL_VERSION_NUM >= 0x073d00
/* In libcurl 7.61.0, support was added for extracting the time in plain
   microseconds. Older libcurl versions are stuck in using 'double' for this
   information so we complicate this example a bit by supporting either
   approach. */
#define TIME_IN_US                              1
#define TIMETYPE                                curl_off_t
#define TIMEOPT                                 CURLINFO_TOTAL_TIME_T
#define MINIMAL_PROGRESS_FUNCTIONALITY_INTERVAL 3000000
#else
#define TIMETYPE                                double
#define TIMEOPT                                 CURLINFO_TOTAL_TIME
#define MINIMAL_PROGRESS_FUNCTIONALITY_INTERVAL 3
#endif

#define STOP_DOWNLOAD_AFTER_THIS_MANY_BYTES 6000

struct myprogress
{
    double lastruntime;
    CURL* curl;
};
int progress_func(void* p,
                  curl_off_t dltotal, curl_off_t dlnow,
                  curl_off_t ultotal, curl_off_t ulnow)
{
    struct myprogress* myp = (struct myprogress*)p;
    CURL* curl = myp->curl;
    curl_off_t curtime = 0;

    if ((curtime - myp->lastruntime) >= MINIMAL_PROGRESS_FUNCTIONALITY_INTERVAL)
    {
        myp->lastruntime = curtime;
#ifdef TIME_IN_US
        fprintf(stderr, "TOTAL TIME: %" CURL_FORMAT_CURL_OFF_T ".%06ld\r\n",
                (curtime / 1000000), (long)(curtime % 1000000));
#else
        fprintf(stderr, "TOTAL TIME: %f \r\n", curtime);
#endif
    }
    fprintf(stderr, "TOTAL TIME: %" CURL_FORMAT_CURL_OFF_T ".%06ld\r\n",
            (curtime / 1000000), (long)(curtime % 1000000));
    fprintf(stderr, "UP: %" CURL_FORMAT_CURL_OFF_T " of %" CURL_FORMAT_CURL_OFF_T "  DOWN: %" CURL_FORMAT_CURL_OFF_T " of %" CURL_FORMAT_CURL_OFF_T "\n",
            ulnow, ultotal, dlnow, dltotal);
    if (dlnow > 700000)
        return 1;
    return 0;
}
int main(void)
{
    CURL* curl;
    CURLcode res;
    struct FtpFile ftpfile = {
        "curl.tar.gz", /* name to store the file as if successful */
        NULL};

    curl_global_init(CURL_GLOBAL_DEFAULT);

    curl = curl_easy_init();
    if (curl)
    {
        struct myprogress prog;
        prog.lastruntime = 0;
        prog.curl = curl;
        /*
     * You better replace the URL with one that works!
     */
        curl_easy_setopt(curl, CURLOPT_URL,
                         "ftp://192.168.65.142/gghc.mp4");
        /* Define our callback to get called when there's data to be written */
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
        /* Set a pointer to our struct to pass to the callback */
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);

        /* Switch on full protocol/debug output */
        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
        curl_easy_setopt(curl, CURLOPT_USERPWD, "<PASSWORD>");

        curl_easy_setopt(curl, CURLOPT_NOPROGRESS, false);               //设为false 下面才能设置进度响应函数
        curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_func); //进度响应函数
        curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &prog);
        //  *CURLOPT_LOW_SPEED_LIMIT:设置一个长整形数，控制传送多少字节。
        //     *CURLOPT_LOW_SPEED_TIME:设置一个长整形数，控制多少秒传送CURLOPT_LOW_SPEED_LIMIT规定的字节数。
        curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 1);
        curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 500);

		//这里限速 100KB/s
		curl_easy_setopt (curl, CURLOPT_MAX_RECV_SPEED_LARGE, (curl_off_t) 20 * 1024);

        res = curl_easy_perform(curl);

        /* always cleanup */
        curl_easy_cleanup(curl);

        if (CURLE_OK != res)
        {
            /* we failed */
            fprintf(stderr, "curl told us %d\n", res);
        }
    }

    if (ftpfile.stream)
        fclose(ftpfile.stream); /* close the local file */

    curl_global_cleanup();

    return 0;
}
{'fraction_non_alphanumeric': 0.14054907677356657, 'fraction_numerical': 0.015184645286686104, 'mean_word_length': 2.307754118119727, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 36, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7307149', 'n_tokens_mistral': 2853, 'n_tokens_neox': 2594, 'n_words': 693}