1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: lib541.c,v 1.1.1.1 2008-09-23 16:32:06 hoffman Exp $
11 #include "setup.h" /* struct_stat etc. */
14 #ifdef HAVE_SYS_SOCKET_H
15 #include <sys/socket.h>
17 #ifdef HAVE_SYS_TYPES_H
18 #include <sys/types.h>
20 #ifdef HAVE_SYS_STAT_H
32 * Two FTP uploads, the second with no content sent.
38 CURLcode res
= CURLE_OK
;
41 struct_stat file_info
;
45 fprintf(stderr
, "Usage: <url> <file-to-upload>\n");
49 /* get the file size of the local file */
50 hd
= stat(libtest_arg2
, &file_info
);
52 /* can't open file, bail out */
54 fprintf(stderr
, "stat() failed with error: %d %s\n",
55 error
, strerror(error
));
56 fprintf(stderr
, "WARNING: cannot open file %s\n", libtest_arg2
);
60 if(! file_info
.st_size
) {
61 fprintf(stderr
, "WARNING: file %s has no size!\n", libtest_arg2
);
65 /* get a FILE * of the same file, could also be made with
66 fdopen() from the previous descriptor, but hey this is just
68 hd_src
= fopen(libtest_arg2
, "rb");
71 fprintf(stderr
, "fopen() failed with error: %d %s\n",
72 error
, strerror(error
));
73 fprintf(stderr
, "Error opening file: %s\n", libtest_arg2
);
74 return -2; /* if this happens things are major weird */
77 if (curl_global_init(CURL_GLOBAL_ALL
) != CURLE_OK
) {
78 fprintf(stderr
, "curl_global_init() failed\n");
80 return TEST_ERR_MAJOR_BAD
;
83 /* get a curl handle */
84 if ((curl
= curl_easy_init()) == NULL
) {
85 fprintf(stderr
, "curl_easy_init() failed\n");
86 curl_global_cleanup();
88 return TEST_ERR_MAJOR_BAD
;
91 /* enable uploading */
92 curl_easy_setopt(curl
, CURLOPT_UPLOAD
, 1L);
95 curl_easy_setopt(curl
, CURLOPT_VERBOSE
, 1L);
98 curl_easy_setopt(curl
,CURLOPT_URL
, URL
);
100 /* now specify which file to upload */
101 curl_easy_setopt(curl
, CURLOPT_INFILE
, hd_src
);
103 /* Now run off and do what you've been told! */
104 res
= curl_easy_perform(curl
);
106 /* and now upload the exact same again, but without rewinding so it already
108 res
= curl_easy_perform(curl
);
110 /* close the local file */
113 curl_easy_cleanup(curl
);
114 curl_global_cleanup();