29 #ifndef NETWORK_FTPUPLOAD_HPP_ 30 #define NETWORK_FTPUPLOAD_HPP_ 32 #include "../Wrapper/Curl.hpp" 34 #ifndef CRAWLSERVPP_TESTING 36 #include "../Helper/Portability/curl.h" 40 #include "FakeCurl/FakeCurl.hpp" 70 const std::string& content,
71 const std::string& url,
72 const std::string& proxy = std::string{},
86 std::size_t
read(
char * bufptr, std::size_t size, std::size_t nitems,
void * userp);
96 void check(CURLcode code);
108 const char * content{
nullptr};
134 const std::string& content,
135 const std::string& url,
136 const std::string& proxy,
142 state.
content = content.c_str();
143 state.
size = content.size();
146 throw std::runtime_error(
"Could not initialize libcurl wrapper");
157 CURLOPT_INFILESIZE_LARGE,
158 static_cast<curl_off_t
>(state.
size)
173 inline std::size_t
read(
char * bufptr, std::size_t size, std::size_t nitems,
void * userp) {
174 auto toRead{size * nitems};
175 auto * state{
static_cast<State *
>(userp)};
176 const auto restSize{state->
size - state->transferred};
178 if(toRead > restSize) {
186 std::memcpy(bufptr, state->content + state->transferred, toRead);
188 state->transferred += toRead;
194 if(code != CURLE_OK) {
195 throw std::runtime_error(curl_easy_strerror(code));
void write(const std::string &content, const std::string &url, const std::string &proxy=std::string{}, bool verbose=false)
Writes data into a FTP file using the libcurl library.
Definition: FTPUpload.hpp:133
std::size_t read(char *bufptr, std::size_t size, std::size_t nitems, void *userp)
Custom reader function for FTP transfers.
Definition: FTPUpload.hpp:173
void check(CURLcode code)
Checks the result of a libcurl operation and throws an exception if an error occured.
Definition: FTPUpload.hpp:193
bool valid() const noexcept
Checks whether the underlying libcurl handle is valid.
Definition: Curl.hpp:214
Definition: FTPUpload.hpp:49
State & operator=(State &)=delete
Deleted copy operator.
RAII wrapper for handles of the libcurl API.
Definition: Curl.hpp:70
CURL * get() noexcept
Gets a pointer to the underlying libcurl handle.
Definition: Curl.hpp:193
State()=default
Default constructor.
Stores content and status of a FTP upload.
Definition: FTPUpload.hpp:103
std::size_t transferred
Number of bytes that have already been uploaded.
Definition: FTPUpload.hpp:114
const char * content
Constant pointer to the content to be uploaded.
Definition: FTPUpload.hpp:108
std::size_t size
Size of the content to be uploaded.
Definition: FTPUpload.hpp:111