WebDAV Client
Public Member Functions | Static Public Member Functions | List of all members
WebDAV::Client Class Reference

WebDAV Client. More...

#include <client.hpp>

Public Member Functions

auto free_size () const noexcept -> unsigned long long
 
auto check (const std::string &remote_resource="/") const noexcept -> bool
 
auto info (const std::string &remote_resource) const noexcept -> dict_t
 
auto clean (const std::string &remote_resource) const noexcept -> bool
 
auto is_directory (const std::string &remote_resource) const noexcept -> bool
 
auto list (const std::string &remote_directory="") const noexcept -> strings_t
 
auto create_directory (const std::string &remote_directory, bool recursive=false) const noexcept -> bool
 
auto move (const std::string &remote_source_resource, const std::string &remote_destination_resource) const noexcept -> bool
 
auto copy (const std::string &remote_source_resource, const std::string &remote_destination_resource) const noexcept -> bool
 
auto download (const std::string &remote_file, const std::string &local_file, progress_t progress=nullptr) const noexcept -> bool
 
auto download_to (const std::string &remote_file, char *&buffer_ptr, unsigned long long &buffer_size, progress_t progress=nullptr) const noexcept -> bool
 
auto download_to (const std::string &remote_file, std::ostream &stream, progress_t progress=nullptr) const noexcept -> bool
 
auto async_download (const std::string &remote_file, const std::string &local_file, callback_t callback=nullptr, progress_t progress=nullptr) const noexcept -> void
 
auto upload (const std::string &remote_file, const std::string &local_file, progress_t progress=nullptr) const noexcept -> bool
 
auto upload_from (const std::string &remote_file, char *buffer_ptr, unsigned long long buffer_size, progress_t progress=nullptr) const noexcept -> bool
 
auto upload_from (const std::string &remote_file, std::istream &stream, progress_t progress=nullptr) const noexcept -> bool
 
auto async_upload (const std::string &remote_file, const std::string &local_file, callback_t callback=nullptr, progress_t progress=nullptr) const noexcept -> void
 

Static Public Member Functions

static auto Init (const dict_t &options) noexcept -> Client *
 
static void Cleanup () noexcept
 This function releases resources acquired by curl_global_init.
 

Detailed Description

WebDAV Client.

Author
designerror
Version
1.0.1
Date
08/11/2016

Member Function Documentation

◆ async_download()

auto WebDAV::Client::async_download ( const std::string &  remote_file,
const std::string &  local_file,
callback_t  callback = nullptr,
progress_t  progress = nullptr 
) const -> void
noexcept

Asynchronously download a remote file to a local file

Parameters
[in]remote_file
[in]local_file
[in]callback
[in]progress
void async_download_to_file()
{
std::map<std::string, std::string> options =
{
{"webdav_hostname", "https://webdav.yandex.ru"},
{"webdav_username", "{webdav_username}"},
{"webdav_password", "{webdav_password}"}
};
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
std::string remote_file = "dir/file.dat";
std::string local_file = "/home/user/Downloads/file.dat";
client->async_download(remote_file, local_file, [remote_file](bool is_downloaded)
{
std::cout << remote_file << " resource is" << (is_downloaded ? "" : "not") << "downloaded" << std::endl;
});
}

◆ async_upload()

auto WebDAV::Client::async_upload ( const std::string &  remote_file,
const std::string &  local_file,
callback_t  callback = nullptr,
progress_t  progress = nullptr 
) const -> void
noexcept

Asynchronously upload a remote file from a local file

Parameters
[in]remote_file
[in]local_file
[in]callback
[in]progress
void async_upload_from_file()
{
std::map<std::string, std::string> options =
{
{"webdav_hostname", "https://webdav.yandex.ru"},
{"webdav_username", "{webdav_username}"},
{"webdav_password", "{webdav_password}"}
};
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
std::string remote_file = "dir/file.dat";
std::string local_file = "/home/user/Downloads/file.dat";
client->async_upload(remote_file, local_file, [remote_file](bool is_uploaded)
{
std::cout << remote_file << " resource is" << (is_uploaded ? "" : "not") << "uploaded" << std::endl;
});
}

◆ check()

auto WebDAV::Client::check ( const std::string &  remote_resource = "/") const -> bool
noexcept

Check for existence of a remote resource

Parameters
[in]remote_resource
/*#***************************************************************************
# __ __ _____ _____
# Project | | | | | \ / ___|
# | |__| | | |\ \ / /
# | | | | ) ) ( (
# | /\ | | |/ / \ \___
# \_/ \_/ |_____/ \_____|
#
# Copyright (C) 2016, The WDC Project, <designerror@yandex.ru>, et al.
#
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the LICENSE file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
############################################################################*/
#include <webdav/client.hpp>
int main() {
auto hostname_ptr = std::getenv("WEBDAV_HOSTNAME");
auto username_ptr = std::getenv("WEBDAV_USERNAME");
auto password_ptr = std::getenv("WEBDAV_PASSWORD");
auto root_ptr = std::getenv("WEBDAV_ROOT");
if (hostname_ptr == nullptr) return -1;
if (username_ptr == nullptr) return -1;
if (password_ptr == nullptr) return -1;
std::map<std::string, std::string> options =
{
{ "webdav_hostname", hostname_ptr },
{ "webdav_username", username_ptr },
{ "webdav_password", password_ptr }
};
if (root_ptr != nullptr) {
options["webdav_root"] = root_ptr;
}
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
auto remote_resources = {
"existing_file.dat",
"not_existing_file.dat",
"existing_directory",
"existing_directory/",
"not_existing_directory",
"not_existing_directory/"
};
for (auto remote_resource : remote_resources) {
bool is_existed = client->check(remote_resource);
std::cout << "Resource: " << remote_resource << " is " << (is_existed ? "" : "not ") << "existed" << std::endl;
}
}

◆ clean()

auto WebDAV::Client::clean ( const std::string &  remote_resource) const -> bool
noexcept

Clean an remote resource

Parameters
[in]remote_resource

◆ copy()

auto WebDAV::Client::copy ( const std::string &  remote_source_resource,
const std::string &  remote_destination_resource 
) const -> bool
noexcept

Copy a remote resource

Parameters
[in]remote_source_resource
[in]remote_destination_resource
/*#***************************************************************************
# __ __ _____ _____
# Project | | | | | \ / ___|
# | |__| | | |\ \ / /
# | | | | ) ) ( (
# | /\ | | |/ / \ \___
# \_/ \_/ |_____/ \_____|
#
# Copyright (C) 2016, The WDC Project, <designerror@yandex.ru>, et al.
#
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the LICENSE file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
############################################################################*/
#include <webdav/client.hpp>
#include <sstream>
std::string resources_to_string(std::vector<std::string> & resources)
{
std::stringstream stream;
for (auto resource : resources)
{
stream << "\t" << "- " << resource << std::endl;
}
return stream.str();
}
int main() {
auto hostname_ptr = std::getenv("WEBDAV_HOSTNAME");
auto username_ptr = std::getenv("WEBDAV_USERNAME");
auto password_ptr = std::getenv("WEBDAV_PASSWORD");
auto root_ptr = std::getenv("WEBDAV_ROOT");
if (hostname_ptr == nullptr) return -1;
if (username_ptr == nullptr) return -1;
if (password_ptr == nullptr) return -1;
std::map<std::string, std::string> options =
{
{ "webdav_hostname", hostname_ptr },
{ "webdav_username", username_ptr },
{ "webdav_password", password_ptr }
};
if (root_ptr != nullptr) {
options["webdav_root"] = root_ptr;
}
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
auto remote_file = "file.dat";
auto remote_directory = "dir/";
auto copy_remote_file = "file2.dat";
auto copy_remote_directory = "dir2/";
auto resources = client->list();
std::cout << "\"/\" resource contain:" << std::endl;
std::cout << resources_to_string(resources) << std::endl;
client->copy(remote_file, copy_remote_file);
client->copy(remote_directory, copy_remote_directory);
resources = client->list();
std::cout << "\"/\" resource contain:" << std::endl;
std::cout << resources_to_string(resources) << std::endl;
}

◆ create_directory()

auto WebDAV::Client::create_directory ( const std::string &  remote_directory,
bool  recursive = false 
) const -> bool
noexcept

Create a remote directory

Parameters
[in]remote_directory
[in]recursive
/*#***************************************************************************
# __ __ _____ _____
# Project | | | | | \ / ___|
# | |__| | | |\ \ / /
# | | | | ) ) ( (
# | /\ | | |/ / \ \___
# \_/ \_/ |_____/ \_____|
#
# Copyright (C) 2016, The WDC Project, <designerror@yandex.ru>, et al.
#
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the LICENSE file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
############################################################################*/
#include <webdav/client.hpp>
int main() {
std::map<std::string, std::string> options =
{
{ "webdav_hostname", "https://webdav.yandex.ru" },
{ "webdav_username", "{webdav_username}" },
{ "webdav_password", "{webdav_password}" }
};
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
auto remote_directories = {
"existing_directory",
"existing_directory/new_directory",
"not_existing_directory/new_directory",
};
for (auto remote_directory : remote_directories) {
bool is_created = client->create_directory(remote_directory);
std::cout << "Directory: " << remote_directory << " is " << (is_created ? "" : "not ") << "created" << std::endl;
}
auto remote_directory = "not_existing_directory/new_directory";
bool recursive = true;
bool is_created = client->create_directory("not_existing_directory/new_directory", recursive);
std::cout << "Directory: " << remote_directory << " is " << (is_created ? "" : "not ") << "created" << std::endl;
}

◆ download()

auto WebDAV::Client::download ( const std::string &  remote_file,
const std::string &  local_file,
progress_t  progress = nullptr 
) const -> bool
noexcept

Download a remote file to a local file

Parameters
[in]remote_file
[in]local_file
[in]progress
void download_to_file()
{
std::map<std::string, std::string> options =
{
{"webdav_hostname", "https://webdav.yandex.ru"},
{"webdav_username", "{webdav_username}"},
{"webdav_password", "{webdav_password}"}
};
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
std::string remote_file = "dir/file.dat";
auto local_file = "/home/user/Downloads/file.dat";
bool is_downloaded = client->download(remote_file, local_file);
std::cout << remote_file << " resource is" << (is_downloaded ? "" : "not") << "downloaded" << std::endl;
}

◆ download_to() [1/2]

auto WebDAV::Client::download_to ( const std::string &  remote_file,
char *&  buffer_ptr,
unsigned long long &  buffer_size,
progress_t  progress = nullptr 
) const -> bool
noexcept

Download a remote file to a buffer

Parameters
[in]remote_file
[out]buffer_ptr
[out]buffer_size
[in]progress
void download_to_buffer()
{
std::map<std::string, std::string> options =
{
{"webdav_hostname", "https://webdav.yandex.ru"},
{"webdav_username", "{webdav_username}"},
{"webdav_password", "{webdav_password}"}
};
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
std::string remote_file = "dir/file.dat";
char * buffer_ptr = nullptr;
unsigned long long buffer_size = 0;
bool is_downloaded = client->download_to(remote_file, buffer_ptr, buffer_size);
std::cout << remote_file << " resource is" << (is_downloaded ? "" : "not") << "downloaded" << std::endl;
}

◆ download_to() [2/2]

auto WebDAV::Client::download_to ( const std::string &  remote_file,
std::ostream &  stream,
progress_t  progress = nullptr 
) const -> bool
noexcept

Download a remote file to a stream

Parameters
[in]remote_file
[out]stream
[in]progress

◆ free_size()

auto WebDAV::Client::free_size ( ) const -> unsigned long long
noexcept

Get free size of the WebDAV server

Returns
size in bytes
/*#***************************************************************************
# __ __ _____ _____
# Project | | | | | \ / ___|
# | |__| | | |\ \ / /
# | | | | ) ) ( (
# | /\ | | |/ / \ \___
# \_/ \_/ |_____/ \_____|
#
# Copyright (C) 2016, The WDC Project, <designerror@yandex.ru>, et al.
#
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the LICENSE file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
############################################################################*/
#include <webdav/client.hpp>
int main() {
std::map<std::string, std::string> options =
{
{ "webdav_hostname", "https://webdav.yandex.ru" },
{ "webdav_username", "{webdav_username}" },
{ "webdav_password", "{webdav_password}" }
};
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
auto free_size = client->free_size();
std::cout << "Free size: " << free_size << " bytes" << std::endl;
}

◆ info()

auto WebDAV::Client::info ( const std::string &  remote_resource) const -> dict_t
noexcept

Get information of a remote resource

Parameters
[in]remote_resource
/*#***************************************************************************
# __ __ _____ _____
# Project | | | | | \ / ___|
# | |__| | | |\ \ / /
# | | | | ) ) ( (
# | /\ | | |/ / \ \___
# \_/ \_/ |_____/ \_____|
#
# Copyright (C) 2016, The WDC Project, <designerror@yandex.ru>, et al.
#
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the LICENSE file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
############################################################################*/
#include <webdav/client.hpp>
#include <sstream>
std::string info_to_string(std::map<std::string, std::string> & info) {
std::stringstream stream;
for (auto& option : info){
stream << "/t" << option.first << ": " << option.second << std::endl;
}
return stream.str();
}
int main() {
auto hostname_ptr = std::getenv("WEBDAV_HOSTNAME");
auto username_ptr = std::getenv("WEBDAV_USERNAME");
auto password_ptr = std::getenv("WEBDAV_PASSWORD");
auto root_ptr = std::getenv("WEBDAV_ROOT");
if (hostname_ptr == nullptr) return -1;
if (username_ptr == nullptr) return -1;
if (password_ptr == nullptr) return -1;
std::map<std::string, std::string> options =
{
{ "webdav_hostname", hostname_ptr },
{ "webdav_username", username_ptr },
{ "webdav_password", password_ptr }
};
if (root_ptr != nullptr) {
options["webdav_root"] = root_ptr;
}
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
auto remote_resources = {
"existing_file.dat",
"not_existing_file.dat",
"existing_directory",
"not_existing_directory"
};
for (auto remote_resource : remote_resources)
{
auto info = client->info(remote_resource);
std::cout << "Information about " << remote_resource << ":" << std::endl;
std::cout << info_to_string(info);
std::cout << std::endl;
}
}

◆ Init()

static auto WebDAV::Client::Init ( const dict_t &  options) -> Client *
staticnoexcept
Parameters
[in]webdav_hostname
[in]webdav_root
[in]webdav_username
[in]webdav_password
[in]proxy_hostname
[in]proxy_username
[in]proxy_password
[in]cert_path
[in]key_path
/*#***************************************************************************
# __ __ _____ _____
# Project | | | | | \ / ___|
# | |__| | | |\ \ / /
# | | | | ) ) ( (
# | /\ | | |/ / \ \___
# \_/ \_/ |_____/ \_____|
#
# Copyright (C) 2016, The WDC Project, <designerror@yandex.ru>, et al.
#
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the LICENSE file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
############################################################################*/
#include <webdav/client.hpp>
#include <sstream>
std::map<std::string, std::string> base_options =
{
{ "webdav_hostname", "https://webdav.yandex.ru" },
{ "webdav_username", "{webdav_username}" },
{ "webdav_password", "{webdav_password}" }
};
std::map<std::string, std::string> options_with_proxy =
{
{ "webdav_hostname", "https://webdav.yandex.ru" },
{ "webdav_username", "{webdav_username}" },
{ "webdav_password", "{webdav_password}" },
{ "proxy_hostname", "https://10.0.0.1:8080" },
{ "proxy_username", "{proxy_username}" },
{ "proxy_password", "{proxy_password}" }
};
std::map<std::string, std::string> options_with_cert =
{
{ "webdav_hostname", "https://webdav.yandex.ru" },
{ "webdav_username", "{webdav_username}" },
{ "webdav_password", "{webdav_password}" },
{ "cert_path", "/etc/ssl/certs/client.crt" },
{ "key_path", "/etc/ssl/private/client.key" }
};
std::string options_to_string(const std::map<std::string, std::string> & options) {
std::stringstream stream;
for (auto option :options)
{
stream << "\t" << option.first << ": " << option.second << std::endl;
}
return stream.str();
}
int main() {
auto various_options = {
base_options,
options_with_proxy,
options_with_cert
};
for (auto options : various_options) {
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
bool is_connected = client->check();
std::cout << "Client with options: " << std::endl;
std::cout << options_to_string(options);
std::cout << " is " << (is_connected ? " " : "not ") << "connected" << std::endl;
std::cout << std::endl;
}
}

◆ is_directory()

auto WebDAV::Client::is_directory ( const std::string &  remote_resource) const -> bool
noexcept

Checks whether the resource directory

Parameters
[in]remote_resource

◆ list()

auto WebDAV::Client::list ( const std::string &  remote_directory = "") const -> strings_t
noexcept

List a remote directory

Parameters
[in]remote_directory
/*#***************************************************************************
# __ __ _____ _____
# Project | | | | | \ / ___|
# | |__| | | |\ \ / /
# | | | | ) ) ( (
# | /\ | | |/ / \ \___
# \_/ \_/ |_____/ \_____|
#
# Copyright (C) 2016, The WDC Project, <designerror@yandex.ru>, et al.
#
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the LICENSE file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
############################################################################*/
#include <webdav/client.hpp>
#include <sstream>
std::string resources_to_string(std::vector<std::string> & resources)
{
std::stringstream ss;
for (auto& resource : resources){
ss << "\t" << "- " << resource << std::endl;
}
return ss.str();
}
int main() {
auto hostname_ptr = std::getenv("WEBDAV_HOSTNAME");
auto username_ptr = std::getenv("WEBDAV_USERNAME");
auto password_ptr = std::getenv("WEBDAV_PASSWORD");
auto root_ptr = std::getenv("WEBDAV_ROOT");
if (hostname_ptr == nullptr) return -1;
if (username_ptr == nullptr) return -1;
if (password_ptr == nullptr) return -1;
std::map<std::string, std::string> options =
{
{ "webdav_hostname", hostname_ptr },
{ "webdav_username", username_ptr },
{ "webdav_password", password_ptr }
};
if (root_ptr != nullptr) {
options["webdav_root"] = root_ptr;
}
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
auto remote_resources = {
"/",
"existing_file.dat",
"not_existing_file.dat",
"existing_directory",
"not_existing_directory"
};
for (auto& remote_resource : remote_resources) {
auto resources = client->list(remote_resource);
std::cout << remote_resource << " resource contain:" << std::endl;
std::cout << resources_to_string(resources);
std::cout << std::endl;
}
}

◆ move()

auto WebDAV::Client::move ( const std::string &  remote_source_resource,
const std::string &  remote_destination_resource 
) const -> bool
noexcept

Move a remote resource

Parameters
[in]remote_source_resource
[in]remote_destination_resource
/*#***************************************************************************
# __ __ _____ _____
# Project | | | | | \ / ___|
# | |__| | | |\ \ / /
# | | | | ) ) ( (
# | /\ | | |/ / \ \___
# \_/ \_/ |_____/ \_____|
#
# Copyright (C) 2016, The WDC Project, <designerror@yandex.ru>, et al.
#
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the LICENSE file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
############################################################################*/
#include <webdav/client.hpp>
#include <sstream>
std::string resources_to_string(const std::vector<std::string> & resources) {
std::stringstream stream;
for (auto resource : resources)
{
stream << "\t" << "- " << resource << std::endl;
}
return stream.str();
}
int main() {
std::map<std::string, std::string> options =
{
{ "webdav_hostname", "https://webdav.yandex.ru" },
{ "webdav_username", "{webdav_username}" },
{ "webdav_password", "{webdav_password}" }
};
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
auto remote_file = "file.dat";
auto remote_directory = "dir/";
auto new_remote_file = "file2.dat";
auto new_remote_directory = "dir2/";
auto resources = client->list();
std::cout << "\"/\" resource contain:" << std::endl;
std::cout << resources_to_string(resources) << std::endl;
client->move(remote_file, new_remote_file);
client->move(remote_directory, new_remote_directory);
resources = client->list();
std::cout << "\"/\" resource contain:" << std::endl;
std::cout << resources_to_string(resources) << std::endl;
}

◆ upload()

auto WebDAV::Client::upload ( const std::string &  remote_file,
const std::string &  local_file,
progress_t  progress = nullptr 
) const -> bool
noexcept

Upload a remote file from a local file

Parameters
[in]remote_file
[in]local_file
[in]progress
void upload_from_file()
{
std::map<std::string, std::string> options =
{
{"webdav_hostname", "https://webdav.yandex.ru"},
{"webdav_username", "{webdav_username}"},
{"webdav_password", "{webdav_password}"}
};
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
std::string remote_file = "dir/file.dat";
std::string local_file = "/home/user/Downloads/file.dat";
bool is_uploaded = client->upload(remote_file, local_file);
std::cout << remote_file << " resource is" << (is_uploaded ? "" : "not") << "uploaded" << std::endl;
}

◆ upload_from() [1/2]

auto WebDAV::Client::upload_from ( const std::string &  remote_file,
char *  buffer_ptr,
unsigned long long  buffer_size,
progress_t  progress = nullptr 
) const -> bool
noexcept

Upload a remote file from a buffer

Parameters
[in]remote_file
[in]buffer_ptr
[in]buffer_size
[in]progress
void upload_from_buffer()
{
std::map<std::string, std::string> options =
{
{"webdav_hostname", "https://webdav.yandex.ru"},
{"webdav_username", "{webdav_username}"},
{"webdav_password", "{webdav_password}"}
};
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
std::string remote_file = "dir/file.dat";
char * buffer_ptr = nullptr;
unsigned long long buffer_size = 0;
bool is_uploaded = client->upload_from(remote_file, buffer_ptr, buffer_size);
std::cout << remote_file << " resource is" << (is_uploaded ? "" : "not") << "uploaded" << std::endl;
}

◆ upload_from() [2/2]

auto WebDAV::Client::upload_from ( const std::string &  remote_file,
std::istream &  stream,
progress_t  progress = nullptr 
) const -> bool
noexcept

Upload a remote file from a stream

Parameters
[in]remote_file
[in]stream
[in]progress
void upload_from_stream()
{
std::map<std::string, std::string> options =
{
{"webdav_hostname", "https://webdav.yandex.ru"},
{"webdav_username", "{webdav_username}"},
{"webdav_password", "{webdav_password}"}
};
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
std::string remote_file = "dir/file.dat";
std::ifstream stream("/home/user/Downloads/file.dat");
bool is_uploaded = client->upload_from(remote_file, stream);
std::cout << remote_file << " resource is" << (is_uploaded ? "" : "not") << "uploaded" << std::endl;
}

The documentation for this class was generated from the following file: