Implement FTP uploading
This commit is contained in:
parent
a067e36cc5
commit
85607bc50b
@ -18,20 +18,75 @@
|
|||||||
#include "cmCTestSubmit.h"
|
#include "cmCTestSubmit.h"
|
||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
|
|
||||||
bool cmCTestSubmit::SubmitUsingFTP(const std::vector<std::string>& files,
|
#include "curl/curl.h"
|
||||||
const std::string& prefix,
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
bool cmCTestSubmit::SubmitUsingFTP(const std::string& localprefix,
|
||||||
|
const std::vector<std::string>& files,
|
||||||
|
const std::string& remoteprefix,
|
||||||
const std::string& url)
|
const std::string& url)
|
||||||
{
|
{
|
||||||
std::string::size_type cc;
|
CURL *curl;
|
||||||
for ( cc = 0; cc < files.size(); cc ++ )
|
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)
|
||||||
{
|
{
|
||||||
std::cout << "upload file: " << files[cc].c_str() << " to " << url.c_str()
|
// enable uploading
|
||||||
<< " / " << prefix.c_str() << " " << files[cc].c_str() << std::endl;
|
::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);
|
||||||
}
|
}
|
||||||
|
::curl_global_cleanup();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmCTestSubmit::SubmitUsingSCP(const std::vector<std::string>& files,
|
bool cmCTestSubmit::SubmitUsingSCP(const std::string& localprefix,
|
||||||
const std::string& prefix,
|
const std::vector<std::string>& files,
|
||||||
|
const std::string& remoteprefix,
|
||||||
const std::string& url)
|
const std::string& url)
|
||||||
{
|
{
|
||||||
std::cout << "SubmitUsingSCP is not yet implemented" << std::endl;
|
std::cout << "SubmitUsingSCP is not yet implemented" << std::endl;
|
||||||
|
@ -34,10 +34,14 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Submit file using various ways
|
* Submit file using various ways
|
||||||
*/
|
*/
|
||||||
bool SubmitUsingFTP(const std::vector<std::string>& files,
|
bool SubmitUsingFTP(const std::string& localprefix,
|
||||||
const std::string& prefix, const std::string& url);
|
const std::vector<std::string>& files,
|
||||||
bool SubmitUsingSCP(const std::vector<std::string>& files,
|
const std::string& remoteprefix,
|
||||||
const std::string& prefix, const std::string& url);
|
const std::string& url);
|
||||||
|
bool SubmitUsingSCP(const std::string& localprefix,
|
||||||
|
const std::vector<std::string>& files,
|
||||||
|
const std::string& remoteprefix,
|
||||||
|
const std::string& url);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user