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 hd_src = fopen(libtest_arg2, "rb");
52 fprintf(stderr, "fopen() failed with error: %d %s\n",
53 error, strerror(error));
54 fprintf(stderr, "Error opening file: %s\n", libtest_arg2);
55 return -2; /* if this happens things are major weird */
58 /* get the file size of the local file */
59 hd = fstat(fileno(hd_src), &file_info);
61 /* can't open file, bail out */
63 fprintf(stderr, "fstat() failed with error: %d %s\n",
64 error, strerror(error));
65 fprintf(stderr, "ERROR: cannot open file %s\n", libtest_arg2);
70 if(! file_info.st_size) {
71 fprintf(stderr, "ERROR: file %s has zero size!\n", libtest_arg2);
76 if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
77 fprintf(stderr, "curl_global_init() failed\n");
79 return TEST_ERR_MAJOR_BAD;
82 /* get a curl handle */
83 if ((curl = curl_easy_init()) == NULL) {
84 fprintf(stderr, "curl_easy_init() failed\n");
85 curl_global_cleanup();
87 return TEST_ERR_MAJOR_BAD;
90 /* enable uploading */
91 test_setopt(curl, CURLOPT_UPLOAD, 1L);
94 test_setopt(curl, CURLOPT_VERBOSE, 1L);
97 test_setopt(curl,CURLOPT_URL, URL);
99 /* now specify which file to upload */
100 test_setopt(curl, CURLOPT_INFILE, hd_src);
102 /* Now run off and do what you've been told! */
103 res = curl_easy_perform(curl);
105 /* and now upload the exact same again, but without rewinding so it already
107 res = curl_easy_perform(curl);
111 /* close the local file */
114 curl_easy_cleanup(curl);
115 curl_global_cleanup();