cURL / Mailing Lists / curl-library / Single Mail


HTTP PUT again...

From: martin hilpert <>
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 = "";
  /* 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 */

  /* 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);
  fclose(hd_src); /* close the local file */
  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 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!
Received on 2003-12-16