CURLOPT_INFILESIZE(3)

✨ CURLOPT_INFILESIZE(3) ✨

okay so real talk, this one lives in the Library Functions Manual and it's genuinely one of the most useful little knobs in the whole libcurl lineup. bestie, let me put you on πŸ’…


πŸ’– NAME πŸ’–

CURLOPT_INFILESIZE β€” literally just "how big is the file I'm sending off" πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_INFILESIZE, long filesize);

🌸 DESCRIPTION 🌸

So when you're uploading a file to a remote site, filesize is the thing you pass to tell libcurl what the expected size of the input file is. That value must be passed as a long β€” no vibes-only guessing, actual type, okay? πŸ’… And if you're out here with files bigger than 2GB, go look at CURLOPT_INFILESIZE_LARGE(3) instead, that's the big-girl option 😌

Ngl, for uploading using SCP, this option or CURLOPT_INFILESIZE_LARGE(3) is mandatory. Not optional. Not a suggestion. Mandatory. 🫢

Wanna unset this value again later? Set it to -1. That's it, that's the whole trick ✨

And here's a fun one: if you're using CURLOPT_UPLOAD(3) to an HTTP/1.1 server and this value is set to -1, libcurl does a chunked transfer-encoded upload. it's giving "no size, no problem" πŸ”₯

When sending emails using SMTP, this command can be used to specify the optional SIZE parameter for the MAIL FROM command. cute, right? πŸŽ€

⚠️ Okay important, listen up: this option does not limit how much data libcurl actually sends. That is controlled entirely by what the read callback returns. But telling one value and then sending a different amount may lead to errors. so like… don't lie to libcurl, she remembers πŸ’€

πŸŽ€ DEFAULT πŸŽ€

Unset ✨ (living that unbothered no-value life)


🌈 PROTOCOLS 🌈

This functionality affects all supported protocols. all of them. every single one. slay πŸ‘‘


🧚 EXAMPLE 🧚

#define FILE_SIZE 12345L

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    long uploadsize = FILE_SIZE;

    curl_easy_setopt(curl, CURLOPT_URL,
                     "ftp://example.com/destination.tar.gz");

    curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);

    curl_easy_setopt(curl, CURLOPT_INFILESIZE, uploadsize);

    curl_easy_perform(curl);
  }
}

look at her go πŸ˜­πŸ’– fully iconic, no notes.


πŸ•°οΈ HISTORY πŸ•°οΈ

  • SMTP support added in 7.23.0 πŸ“¬

⭐ AVAILABILITY ⭐

Added in curl 7.1. vintage. a classic. the main character of early curl 🫢


πŸ’œ RETURN VALUE πŸ’œ

curl_easy_setopt(3) returns a CURLcode indicating success or error 😌

  • CURLE_OK (which is 0) means everything was OK β€” we love a zero πŸ’š
  • non-zero means an error occurred β€” go check libcurl-errors(3) for the tea πŸ’€

πŸ‘€ SEE ALSO πŸ‘€


and that's the page, bestie! πŸ¦‹ this lil gem comes to you courtesy of libcurl, dated 2026-10-12, and the page itself is CURLOPT_INFILESIZE(3) β€” go forth and tell libcurl your file size, she'll appreciate the honesty πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from