1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
12 #ifdef HAVE_SYS_SOCKET_H
13 #include <sys/socket.h>
15 #ifdef HAVE_SYS_TYPES_H
16 #include <sys/types.h>
18 #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 test_setopt(curl, CURLOPT_UPLOAD, 1L);
95 test_setopt(curl, CURLOPT_VERBOSE, 1L);
98 test_setopt(curl,CURLOPT_URL, URL);
100 /* now specify which file to upload */
101 test_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);
112 /* close the local file */
115 curl_easy_cleanup(curl);
116 curl_global_cleanup();