curl / Mailing Lists / curl-library / Single Mail


SMB: unable to upload file to a subfolder: remote file not found

From: Ivan Pilipenko <>
Date: Fri, 18 May 2018 13:34:44 +0200 (CEST)


I have an implementation of a tool that uses libcurl 7.60.0 to upload report files to an FTP server, creating subdirectories as needed. So far this has been working fine, but now we also got a request to do the same using SMB.

The implementation I got so far manages to upload a file to a share's root folder, i.e. "smb://myserver/share/test.txt", but fails when attempting to upload the file to an _existing_ subfolder, i.e. "smb://myserver/share/testfolder/test.txt".

This is my code so far (relevant excerpt):

// reset all parameters

// set username and password
string userPwd = user + ":" + password;
setCurlOption(CURLOPT_USERPWD, userPwd);

// we want to use our own read function
setCurlOption(CurlOption(CURLOPT_READFUNCTION, readCallbackFunction));

// enable uploading
setCurlOption(CurlOption(CURLOPT_UPLOAD, 1L));

// iterate over all NamedDataElements
for(const auto& namedData : namedDataElements) {
    // create pair<NamedData*, uint32> with read position for this NamedData
    if(namedData == nullptr) {

    pair<NamedData*, uint32> namedDataReadPos = make_pair(namedData.get(), 0);

    // now specify which namedData to upload
    setCurlOption(CurlOption(CURLOPT_READDATA, &namedDataReadPos));

    // set the size of the namedData
    curl_off_t dataLength = static_cast<curl_off_t>(namedData->getLength());
    setCurlOption(CurlOption(CURLOPT_INFILESIZE_LARGE, dataLength));

    string filename = "smb://server/share/testfolder/test.txt";
    setCurlOption(CurlOption(CURLOPT_URL, filename));

    // provide a buffer to store errors in and set the error buffer to empty before performing a request
    std::fill_n(errorBuffer, CURL_ERROR_SIZE + 1, '\0');
    try {
        setCurlOption(CURLOPT_ERRORBUFFER, errorBuffer);
    catch(const MvException&) {
        if(doThrow) {
            // rethrow

    auto result = curl_easy_perform(curl);
    if(CURLE_OK != result && doThrow == true) {
        throwCurlStatus(result, __FUNCTION__, __LINE__, errorBuffer);

Executing results in "CURL error: Remote file not found", errorBuffer is empty. I am not quite sure why this error message is returned by libcurl. Obviously, the remote file might not exist when I'm attempting to upload one?

Any help is appreciated.

Upcoming Events:
19.-22. June: AUTOMATICA, Munich, Germany
06.-08. November: VISION, Stuttgart, Germany

MATRIX VISION GmbH, Talstrasse 16, DE-71570 Oppenweiler
Registergericht: Amtsgericht Stuttgart, HRB 271090
Geschaeftsfuehrer: Uwe Furtner
Received on 2018-05-18