curltest.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include "curl/curl.h"
  2. int GetFtpFile(void)
  3. {
  4. int retVal = 0;
  5. CURL *curl;
  6. CURLcode res;
  7. curl = curl_easy_init();
  8. if(curl)
  9. {
  10. /* Get curl 7.9.2 from sunet.se's FTP site: */
  11. curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  12. curl_easy_setopt(curl, CURLOPT_HEADER, 1);
  13. curl_easy_setopt(curl, CURLOPT_URL,
  14. "ftp://public.kitware.com/pub/cmake/cygwin/setup.hint");
  15. res = curl_easy_perform(curl);
  16. if ( res != 0 )
  17. {
  18. printf("Error fetching: ftp://public.kitware.com/pub/cmake/cygwin/setup.hint\n");
  19. retVal = 1;
  20. }
  21. /* always cleanup */
  22. curl_easy_cleanup(curl);
  23. }
  24. else
  25. {
  26. printf("Cannot create curl object\n");
  27. retVal = 1;
  28. }
  29. return retVal;
  30. }
  31. int GetWebFile(void)
  32. {
  33. int retVal = 0;
  34. CURL *curl;
  35. CURLcode res;
  36. curl = curl_easy_init();
  37. if(curl)
  38. {
  39. curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  40. curl_easy_setopt(curl, CURLOPT_HEADER, 1);
  41. /* get the first document */
  42. curl_easy_setopt(curl, CURLOPT_URL, "http://www.cmake.org/page1.html");
  43. res = curl_easy_perform(curl);
  44. if ( res != 0 )
  45. {
  46. printf("Error fetching: http://www.cmake.org/page1.html\n");
  47. retVal = 1;
  48. }
  49. /* get another document from the same server using the same
  50. connection */
  51. curl_easy_setopt(curl, CURLOPT_URL, "http://www.cmake.org/page2.html");
  52. res = curl_easy_perform(curl);
  53. if ( res != 0 )
  54. {
  55. printf("Error fetching: http://www.cmake.org/page2.html\n");
  56. retVal = 1;
  57. }
  58. /* always cleanup */
  59. curl_easy_cleanup(curl);
  60. }
  61. else
  62. {
  63. printf("Cannot create curl object\n");
  64. retVal = 1;
  65. }
  66. return retVal;
  67. }
  68. int main(int argc, char **argv)
  69. {
  70. int retVal = 0;
  71. curl_global_init(CURL_GLOBAL_DEFAULT);
  72. retVal += GetWebFile();
  73. retVal += GetFtpFile();
  74. curl_global_cleanup();
  75. return retVal;
  76. }