CMake/Source/CTest/cmCTestSubmit.cxx

95 lines
2.9 KiB
C++
Raw Normal View History

2003-01-07 07:07:24 +03:00
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "cmCTestSubmit.h"
#include "cmSystemTools.h"
2003-01-08 06:24:45 +03:00
#include "curl/curl.h"
#include <sys/stat.h>
bool cmCTestSubmit::SubmitUsingFTP(const std::string& localprefix,
const std::vector<std::string>& files,
const std::string& remoteprefix,
2003-01-07 07:07:24 +03:00
const std::string& url)
{
2003-01-08 06:24:45 +03:00
CURL *curl;
CURLcode res;
FILE* ftpfile;
/* In windows, this will init the winsock stuff */
::curl_global_init(CURL_GLOBAL_ALL);
/* get a curl handle */
curl = curl_easy_init();
if(curl)
2003-01-07 07:07:24 +03:00
{
2003-01-08 06:24:45 +03:00
// enable uploading
::curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ;
std::string::size_type cc;
for ( cc = 0; cc < files.size(); cc ++ )
{
std::string local_file = localprefix + "/" + files[cc];
std::string upload_as = url + "/" + remoteprefix + files[cc];
struct stat st;
if ( ::stat(local_file.c_str(), &st) )
{
return false;
}
ftpfile = ::fopen(local_file.c_str(), "rb");
std::cout << "upload file: " << local_file.c_str() << " to "
<< upload_as.c_str() << std::endl;
::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
// specify target
::curl_easy_setopt(curl,CURLOPT_URL, upload_as.c_str());
// now specify which file to upload
::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
// and give the size of the upload (optional)
::curl_easy_setopt(curl, CURLOPT_INFILESIZE, st.st_size);
// Now run off and do what you've been told!
res = ::curl_easy_perform(curl);
fclose(ftpfile);
if ( res )
{
std::cout << "Error when uploading" << std::endl;
::curl_easy_cleanup(curl);
::curl_global_cleanup();
return false;
}
}
// always cleanup
::curl_easy_cleanup(curl);
2003-01-07 07:07:24 +03:00
}
2003-01-08 06:24:45 +03:00
::curl_global_cleanup();
return true;
2003-01-07 07:07:24 +03:00
}
2003-01-08 06:24:45 +03:00
bool cmCTestSubmit::SubmitUsingSCP(const std::string& localprefix,
const std::vector<std::string>& files,
const std::string& remoteprefix,
2003-01-07 07:07:24 +03:00
const std::string& url)
{
std::cout << "SubmitUsingSCP is not yet implemented" << std::endl;
2003-01-10 15:50:29 +03:00
return false;
2003-01-07 07:07:24 +03:00
}