cmCTestSubmit.cxx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCTestSubmit.h"
  14. #include "cmSystemTools.h"
  15. #include "curl/curl.h"
  16. #include <sys/stat.h>
  17. bool cmCTestSubmit::SubmitUsingFTP(const std::string& localprefix,
  18. const std::vector<std::string>& files,
  19. const std::string& remoteprefix,
  20. const std::string& url)
  21. {
  22. CURL *curl;
  23. CURLcode res;
  24. FILE* ftpfile;
  25. /* In windows, this will init the winsock stuff */
  26. ::curl_global_init(CURL_GLOBAL_ALL);
  27. /* get a curl handle */
  28. curl = curl_easy_init();
  29. if(curl)
  30. {
  31. // enable uploading
  32. ::curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ;
  33. std::string::size_type cc;
  34. for ( cc = 0; cc < files.size(); cc ++ )
  35. {
  36. std::string local_file = localprefix + "/" + files[cc];
  37. std::string upload_as = url + "/" + remoteprefix + files[cc];
  38. struct stat st;
  39. if ( ::stat(local_file.c_str(), &st) )
  40. {
  41. return false;
  42. }
  43. ftpfile = ::fopen(local_file.c_str(), "rb");
  44. std::cout << "upload file: " << local_file.c_str() << " to "
  45. << upload_as.c_str() << std::endl;
  46. ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  47. // specify target
  48. ::curl_easy_setopt(curl,CURLOPT_URL, upload_as.c_str());
  49. // now specify which file to upload
  50. ::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
  51. // and give the size of the upload (optional)
  52. ::curl_easy_setopt(curl, CURLOPT_INFILESIZE, st.st_size);
  53. // Now run off and do what you've been told!
  54. res = ::curl_easy_perform(curl);
  55. fclose(ftpfile);
  56. if ( res )
  57. {
  58. std::cout << "Error when uploading" << std::endl;
  59. ::curl_easy_cleanup(curl);
  60. ::curl_global_cleanup();
  61. return false;
  62. }
  63. }
  64. // always cleanup
  65. ::curl_easy_cleanup(curl);
  66. }
  67. ::curl_global_cleanup();
  68. return true;
  69. }
  70. bool cmCTestSubmit::SubmitUsingSCP(const std::string& localprefix,
  71. const std::vector<std::string>& files,
  72. const std::string& remoteprefix,
  73. const std::string& url)
  74. {
  75. std::cout << "SubmitUsingSCP is not yet implemented" << std::endl;
  76. }