FTP error: The connection with the server was reset

I’m using libcurl for FTP. My code seemed to be running fine and files were uploaded as I expected. But after a while, I found the connection went wrong and the error message is here.

FTP Folder Error:
Windows cannot access this folder. Make sure you typed the file name correctly and you have 
permission to access the folder.

Details:
The connection with the server was reset.

I asked my colleague to help fix the server yesterday and my code could upload files again. However, this problem occurred again this morning and I have to wonder if there is something wrong with my code. Here is my code.

#include <iostream>
#include <curl/curl.h>

bool createFtpDirectory(const std::string& url, const std::string& userpwd) {
    CURL* curl;
    CURLcode res;
    bool success = false;

    curl = curl_easy_init();
    if (curl) {
        // Set the URL for the FTP operation
        curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
        // Specify the username and password for the FTP server
        curl_easy_setopt(curl, CURLOPT_USERPWD, userpwd.c_str());
        // Specify the FTP command to create a directory
        curl_easy_setopt(curl, CURLOPT_FTP_CREATE_MISSING_DIRS, CURLFTP_CREATE_DIR);
        // Perform the request
        res = curl_easy_perform(curl);
        if (res != CURLE_OK) {
            std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << std::endl;
        }
        else {
            success = true;
        }
        // Clean up
        curl_easy_cleanup(curl);
    }
    return success;
}

bool uploadFileToFtp(const std::string& url, const std::string& userpwd, const std::string& localFilePath) {
    CURL* curl;
    CURLcode res;
    FILE* hd_src;
    bool success = false;

    // Open the file to be uploaded
    errno_t err = fopen_s(&hd_src, localFilePath.c_str(), "rb");
    if (err != 0 || !hd_src) {
        std::cerr << "Failed to open file: " << localFilePath << std::endl;
        return false;
    }

    curl = curl_easy_init();
    if (curl) {
        // Set the URL for the FTP operation
        curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
        // Specify the username and password for the FTP server
        curl_easy_setopt(curl, CURLOPT_USERPWD, userpwd.c_str());
        // Specify the read callback function
        curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
        curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);
        // Perform the request
        res = curl_easy_perform(curl);
        if (res != CURLE_OK) {
            std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << std::endl;
        }
        else {
            success = true;
        }
        // Clean up
        curl_easy_cleanup(curl);
    }

    fclose(hd_src);
    return success;
}

int main() {
    const std::string ftpUrl = "ftp://MY_FTP_PATH";
    const std::string ftpFileUrl = "ftp://MY_FILE_PATH/template.xlsx";
    const std::string userpwd = "USER:PWD";
    const std::string localFilePath = "template.xlsx";

    // Create directory on FTP server
    if (createFtpDirectory(ftpUrl, userpwd)) {
        std::cout << "Directory created successfully." << std::endl;
    }
    else {
        std::cerr << "Failed to create directory." << std::endl;
        return 1;
    }

    // Upload file to FTP server
    if (uploadFileToFtp(ftpFileUrl, userpwd, localFilePath)) {
        std::cout << "File uploaded successfully." << std::endl;
    }
    else {
        std::cerr << "Failed to upload file." << std::endl;
        return 1;
    }

    return 0;
}

I hope someone can point out the loopholes in my code, or give me some other ideas to solve this problem.
Thanks in advance to everyone who sees this question.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật