CURLE_WRITE_ERROR (23) An error occurred when writing received data to a local file, or an error was returned to libcurl from a write callback.
My files from the FTP server are not being deleted because of this error. I don't understand what the problem is. If I remove the line "curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);", everything works fine—res will be CURL_OK, but the files will still remain in the FTP directory.
By the way, my FTP server supports the "DELE" command.
CODE:
int Ftp::deleteFile(const std::string& filename, const ServerInfo& server, const std::string& url)
{
CURL* curl;
CURLcode res;
std::string fullRemotePath = url + filename; // url contains e.x. ftp://100.100.1.1/test.123
if (!checkIfFileExists(server, fullRemotePath)) {
return -1;
}
curl = curl_easy_init();
if (!curl) {
return -1;
}
std::string deleCommand = "DELE " + filename; // ex. DELE test.123
curl_easy_setopt(curl, CURLOPT_URL, fullRemotePath.c_str());
curl_easy_setopt(curl, CURLOPT_USERPWD, (wstringToString(server.login) + ":" + wstringToString(server.pass)).c_str());
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, deleCommand.c_str());
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
res = curl_easy_perform(curl);
bool fileStillExists = checkIfFileExists(server, fullRemotePath);
if (res == CURLE_OK) {
if (!fileStillExists) {
logError(stringToWString("[FTP]: File successfully deleted: ") + stringToWString(fullRemotePath));
curl_easy_cleanup(curl);
return 1;
}
else {
logError(stringToWString("[FTP]: The file was not deleted (error while checking): ") + stringToWString(fullRemotePath));
}
}
else {
logError(stringToWString("[FTP]: Error deleting file: ") + stringToWString(curl_easy_strerror(res)));
if (!fileStillExists) {
logError(stringToWString("[FTP]: However, the file no longer exists on the server.: ") + stringToWString(fullRemotePath));
curl_easy_cleanup(curl);
return 1;
}
}
curl_easy_cleanup(curl);
return 0;
}