cURL / Mailing Lists / curl-library / Single Mail

curl-library

HTTP PUT again...

From: martin hilpert <tecart_at_hipposen.de>
Date: Tue, 16 Dec 2003 11:42:29 +0100

Hi, i try to use the libcurl...

i want upload a file to a webserver.
i use MSVC++
i make a new project console application

thats my code:

#include <stdio.h>
#include "stdafx.h"
#include <io.h>
#include <fcntl.h>
#include <sys/stat.h>
#include "curl.h"
 extern "C" {

size_t read_callback(void *ptr, size_t size, size_t nmemb,struct _iobuf *stream)
{
  size_t retcode;
  /* in real-world cases, this would probably get this data differently
     as this fread() stuff is exactly what the library already would do
     by default internally */
  retcode =fread(ptr, size, nmemb, stream);
  fprintf(stderr, "*** We read %d bytes from file\n", retcode);
  return retcode;
}
 }
int main(int argc, char **argv)
{
  CURL *curl;
  CURLcode res;
  FILE *ftpfile;
  FILE * hd_src ;
  int hd ;
  struct stat file_info;

  char *file;
  char *url;
 
  file= "c:\\mysite.htm";
  url = "192.168.0.12/web/test/";
  
  /* get the file size of the local file */
  hd = open(file,O_RDONLY);
  fstat(hd, &file_info);
  close(hd) ;

  /* get a FILE * of the same file, could also be made with
     fdopen() from the previous descriptor, but hey this is just
     an example! */
  hd_src = fopen(file,"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) {
    curl_easy_setopt(curl, CURLOPT_VERBOSE, TRUE);

    curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
    curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ;
    curl_easy_setopt(curl, CURLOPT_PUT, TRUE);
    curl_easy_setopt(curl, CURLOPT_URL, url);
    curl_easy_setopt(curl, CURLOPT_INFILE, hd_src);
    curl_easy_setopt(curl, CURLOPT_INFILESIZE, file_info.st_size);
 res = curl_easy_perform(curl);
 curl_easy_cleanup(curl);
  }
  fclose(hd_src); /* close the local file */
 
  curl_global_cleanup();
  return 0;
}

but i get only a error 403 ..."You don't have permisson to access /web/test/ on this Server"

where is my failure?

-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
Free Linux Tutorials. Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
Received on 2003-12-16