libsshpp v0.1.7
Modern C++17 wrapper for libssh
Loading...
Searching...
No Matches
algorithms.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2#pragma once
3
4#include <sshpp/config.hpp>
5
6#include <sshpp/export.hpp>
7#include <sshpp/result.hpp>
8#include <sshpp/sftp/sftp.hpp>
9#include <sshpp/types.hpp>
10
11#include <cstdint>
12#include <filesystem>
13#include <functional>
14#include <optional>
15#include <string>
16
17namespace sshpp::sftp {
18
19struct Progress {
20 std::uint64_t bytes_done = 0;
21 std::optional<std::uint64_t> bytes_total;
22};
24using ProgressCallback = std::function<bool(const Progress&)>;
25
26enum class Overwrite { fail, replace };
27
34
35SSHPP_API Result<std::uint64_t> try_download(Sftp&, const RemotePath& remote,
36 const std::filesystem::path& local,
37 TransferOptions = {});
38SSHPP_API Result<std::uint64_t> try_upload(Sftp&, const std::filesystem::path& local,
39 const RemotePath& remote, TransferOptions = {});
40SSHPP_API Result<std::string> try_read_file(Sftp&, const RemotePath&, std::size_t limit = 16u << 20);
41SSHPP_API Result<void> try_write_file(Sftp&, const RemotePath&, ByteView,
42 std::filesystem::perms = std::filesystem::perms::owner_read |
43 std::filesystem::perms::owner_write);
44
45struct TreeStats { std::uint64_t files = 0, directories = 0, bytes = 0, skipped = 0; };
46
50SSHPP_API Result<TreeStats> try_download_tree(Sftp&, const RemotePath& remote,
51 const std::filesystem::path& local,
52 TransferOptions = {});
53
54} // namespace sshpp::sftp
55
56#if SSHPP_HEADER_ONLY
58#endif
Definition types.hpp:76
Definition result.hpp:16
The SFTP subsystem session. See docs/design/06 ยง6.2.
Definition sftp.hpp:45
Definition algorithms.ipp:10
Overwrite
Definition algorithms.hpp:26
SSHPP_INLINE Result< std::uint64_t > try_upload(Sftp &sftp, const std::filesystem::path &local, const RemotePath &remote, TransferOptions opts)
Definition algorithms.ipp:69
SSHPP_INLINE Result< TreeStats > try_download_tree(Sftp &sftp, const RemotePath &remote, const std::filesystem::path &local, TransferOptions opts)
Definition algorithms.ipp:133
std::function< bool(const Progress &)> ProgressCallback
Return false to abort the transfer (yields errc::cancelled).
Definition algorithms.hpp:24
SSHPP_INLINE Result< std::string > try_read_file(Sftp &sftp, const RemotePath &path, std::size_t limit)
Definition algorithms.ipp:108
SSHPP_INLINE Result< std::uint64_t > try_download(Sftp &sftp, const RemotePath &remote, const std::filesystem::path &local, TransferOptions opts)
Definition algorithms.ipp:28
SSHPP_INLINE Result< void > try_write_file(Sftp &sftp, const RemotePath &path, ByteView data, std::filesystem::perms perms)
Definition algorithms.ipp:126
Definition algorithms.hpp:19
std::optional< std::uint64_t > bytes_total
Definition algorithms.hpp:21
std::uint64_t bytes_done
Definition algorithms.hpp:20
Definition algorithms.hpp:28
ProgressCallback progress
Definition algorithms.hpp:32
bool preserve_permissions
Definition algorithms.hpp:30
std::size_t chunk_size
Definition algorithms.hpp:31
Overwrite overwrite
Definition algorithms.hpp:29
Definition algorithms.hpp:45
std::uint64_t bytes
Definition algorithms.hpp:45
std::uint64_t directories
Definition algorithms.hpp:45
std::uint64_t files
Definition algorithms.hpp:45
std::uint64_t skipped
Definition algorithms.hpp:45