Hello,
I'm having a problem with my code where it crashes when trying to copy and append the parameter data to the variables used by the program. This problem is unrelated to libCurl which is what I'm using for the uploading procedure. This code is part of a DLL file.
Code:
DLLIMPORT void UploadFile(char *filename, char *newfilename, char *urlDir, char *username, char *password);
{
char *UPLOAD_FILE_AS;
CURL *curl;
CURLcode res;
FILE *hd_src;
strcpy(UPLOAD_FILE_AS, filename); // CRASHES HERE
strcat(urlDir, newfilename); // SAME PROBLEM HERE
struct curl_slist *headerlist=NULL;
char buf_1 [] = "RNFR ";
char buf_2 [] = "RNTO ";
strcat(buf_1, filename); // AND POSSIBLY THESE TWO AS WELL
strcat(buf_2, newfilename);
/* get a FILE * of the same file */
hd_src = fopen(filename, "rb");
/* In windows, this will init the winsock stuff */
curl_global_init(CURL_GLOBAL_ALL);
/* get a curl handle */
curl = curl_easy_init();
if(curl) {
/* build a list of commands to pass to libcurl */
headerlist = curl_slist_append(headerlist, buf_1);
headerlist = curl_slist_append(headerlist, buf_2);
/* we want to use our own read function */
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
/* enable uploading */
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
/* specify target */
curl_easy_setopt(curl,CURLOPT_URL, urlDir);
/* pass in that last of FTP commands to run after the transfer */
curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist);
/* now specify which file to upload */
curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);
/* specify username and password for ftp */
curl_easy_setopt(curl, CURLOPT_USERNAME, username);
curl_easy_setopt(curl, CURLOPT_PASSWORD, password);
/* Now run off and do what you've been told! */
res = curl_easy_perform(curl);
/* clean up the FTP commands list */
curl_slist_free_all (headerlist);
/* always cleanup */
curl_easy_cleanup(curl);
}
fclose(hd_src); /* close the local file */
curl_global_cleanup();
}
Thanks for the help in advance.