lib539.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*****************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * $Id$
  9. */
  10. #include "test.h"
  11. int test(char *URL)
  12. {
  13. CURLcode res;
  14. CURL *curl;
  15. char *newURL;
  16. struct curl_slist *slist;
  17. if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  18. fprintf(stderr, "curl_global_init() failed\n");
  19. return TEST_ERR_MAJOR_BAD;
  20. }
  21. if ((curl = curl_easy_init()) == NULL) {
  22. fprintf(stderr, "curl_easy_init() failed\n");
  23. curl_global_cleanup();
  24. return TEST_ERR_MAJOR_BAD;
  25. }
  26. /*
  27. * Begin with cURL set to use a single CWD to the URL's directory.
  28. */
  29. curl_easy_setopt(curl, CURLOPT_URL, URL);
  30. curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
  31. curl_easy_setopt(curl, CURLOPT_FTP_FILEMETHOD, CURLFTPMETHOD_SINGLECWD);
  32. res = curl_easy_perform(curl);
  33. /*
  34. * Change the FTP_FILEMETHOD option to use full paths rather than a CWD
  35. * command. Alter the URL's path a bit, appending a "./". Use an innocuous
  36. * QUOTE command, after which cURL will CWD to ftp_conn->entrypath and then
  37. * (on the next call to ftp_statemach_act) find a non-zero ftpconn->dirdepth
  38. * even though no directories are stored in the ftpconn->dirs array (after a
  39. * call to freedirs).
  40. */
  41. newURL = strcat (strcpy ((char*)malloc (strlen (URL) + 3),
  42. URL),
  43. "./");
  44. slist = curl_slist_append (NULL, "SYST");
  45. curl_easy_setopt(curl, CURLOPT_URL, newURL);
  46. curl_easy_setopt(curl, CURLOPT_FTP_FILEMETHOD, CURLFTPMETHOD_NOCWD);
  47. curl_easy_setopt(curl, CURLOPT_QUOTE, slist);
  48. res = curl_easy_perform(curl);
  49. curl_slist_free_all(slist);
  50. free(newURL);
  51. curl_easy_cleanup(curl);
  52. curl_global_cleanup();
  53. return (int)res;
  54. }