1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_MAXFILESIZE
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_MAXFILESIZE_LARGE (3)
9  - CURLOPT_MAX_RECV_SPEED_LARGE (3)
10Protocol:
11  - All
12---
13
14# NAME
15
16CURLOPT_MAXFILESIZE - maximum file size allowed to download
17
18# SYNOPSIS
19
20~~~c
21#include <curl/curl.h>
22
23CURLcode curl_easy_setopt(CURL *handle, CURLOPT_MAXFILESIZE, long size);
24~~~
25
26# DESCRIPTION
27
28Pass a long as parameter. This specifies the maximum accepted *size* (in
29bytes) of a file to download. If the file requested is found larger than this
30value, the transfer is aborted and *CURLE_FILESIZE_EXCEEDED* is returned.
31Passing a zero *size* disables this, and passing a negative *size* yields a
32*CURLE_BAD_FUNCTION_ARGUMENT*.
33
34The file size is not always known prior to the download start, and for such
35transfers this option has no effect - even if the file transfer eventually
36ends up being larger than this given limit.
37
38If you want a limit above 2GB, use CURLOPT_MAXFILESIZE_LARGE(3).
39
40Since 8.4.0, this option also stops ongoing transfers if they reach this
41threshold.
42
43# DEFAULT
44
450, meaning disabled.
46
47# EXAMPLE
48
49~~~c
50int main(void)
51{
52  CURL *curl = curl_easy_init();
53  if(curl) {
54    CURLcode ret;
55    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
56    /* refuse to download if larger than 1000 bytes! */
57    curl_easy_setopt(curl, CURLOPT_MAXFILESIZE, 1000L);
58    ret = curl_easy_perform(curl);
59  }
60}
61~~~
62
63# AVAILABILITY
64
65Always
66
67# RETURN VALUE
68
69Returns CURLE_OK if the size passed is valid or CURLE_BAD_FUNCTION_ARGUMENT if
70not.
71