curl-library
delete files after curling
Date: Sun, 15 Aug 2004 19:04:28 -0700
I have a thread dumping data to separate files, then every 5 minutes I
want to use libcurl to transfer the files to a server to be processed.
After a successful transfer I want to delete the file.
The code I currently have transfers files just fine, but when I try to
delete them after a transfer, the first file I list gets transferred
then deleted and then my program hangs.
Here is the code I'm using:
void curlFilesToServer(void){
DIR *d;
struct dirent *pdirent;
char absPath[100] = "";
char newPath[103] = "./";
int retVal;
//now curl it to a remote server
struct curl_httppost* post = NULL;
struct curl_httppost* last = NULL;
CURL *hCURL = curl_easy_init();
d = opendir(logdir);
while ( (pdirent = readdir(d)) != NULL ){
if(!strcmp(pdirent->d_name, ".") || !strcmp(pdirent->d_name, ".."))
continue;
if(!strcmp(filename, pdirent->d_name)) continue;
//printf("%s\n", pdirent->d_name);
strcpy(absPath, logdir);
strcat(absPath, pdirent->d_name);
curl_easy_setopt(hCURL, CURLOPT_URL, "http://stuff.com/test.php");
curl_formadd(&post, &last, CURLFORM_COPYNAME, "user",
CURLFORM_COPYCONTENTS, login, CURLFORM_END);
curl_formadd(&post, &last, CURLFORM_COPYNAME, "pass",
CURLFORM_COPYCONTENTS, pword, CURLFORM_END);
curl_formadd(&post, &last, CURLFORM_COPYNAME, "tracefile",
CURLFORM_FILE, absPath, CURLFORM_END);
curl_easy_setopt(hCURL, CURLOPT_HTTPPOST, post);
retVal = curl_easy_perform(hCURL);
newPath[2] = '\0';
strcat(newPath, absPath);
if( retVal == 0 )
{
unlink(newPath);
printf("newPath=%s\n", newPath);
}
}
}
I'm wondering if the curl_formadd is keeping the file descriptor open
and this is messing up the unlink(). All the files list properly when I
don't try to delete and just list them instead.
-ryan
Received on 2004-08-16