My code connects to the ftp client and uploads a specified file but not the contents of it because there aren't default permissions set for guests to write to files.
So because of this I have to find a way to send a chmod change request to the file after it's been uploaded so that my program can write to it.
But that's my problem is that I don't know what command to send to the file to change the permissions.
I've tried a few things such as CHMOD 777 <file> and such but haven't had any luck.
I know that you send requests with this method:
Code
struct curl_slist* headerlist = NULL;
std::string cmd1 = "";
headerlist = curl_slist_append(headerlist, cmd1.c_str());
curl_easy_opt(curl, CURLOPT_POSTREQUEST, headerlist);
But like I said, I have been unsuccessful with sending a chmod request.
I don't know anything about PHP but I was thinking that maybe there could be a way to pass the file path to a PHP script and change the permissions that way?
Here's the upload code:
Code
bool UploadFile(char* URL, const char* path)
{
CURL * curl;
CURLcode res;
curl_off_t fileSize;
FILE * uploadFile;
std::string RENAME_FILE_TO;
struct stat file_info;
struct curl_slist* headerlist = NULL;
std::string cmd1 = "CHMOD 777 ";
SetNewFileName(RENAME_FILE_TO, URL);
cmd1 += RENAME_FILE_TO;
std::cout << cmd1 << std::endl;
if(stat(path, &file_info))
{
}
fileSize = (curl_off_t)file_info.st_size;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl)
{
uploadFile = fopen(path, "rb");
if(uploadFile != NULL)
{
headerlist = curl_slist_append(headerlist, cmd1.c_str());
curl_easy_setopt(curl, CURLOPT_READFUNCTION, readData);
curl_easy_setopt(curl, CURLOPT_UPLOAD, true);
curl_easy_setopt(curl, CURLOPT_URL, RENAME_FILE_TO.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
curl_easy_setopt(curl, CURLOPT_READDATA, uploadFile);
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)fileSize);
curl_easy_setopt(curl, CURLOPT_VERBOSE, true);
res = curl_easy_perform(curl);
if(res != CURLE_OK)
{
printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
}
fclose(uploadFile);
}
else
{
std::cout << "Failed to open " << path << "!\n";
return false;
}
curl_slist_free_all(headerlist);
curl_easy_cleanup(curl);
}
else
{
std::cout << "Failed to initialize cURL!\n";
return false;
}
curl_global_cleanup();
return true;
}
This post was edited by SelfTaught on Feb 23 2013 10:28pm