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