1#ifndef NEFORCE_NETWORK_FTP_FTP_PROTOCOL_HPP__
2#define NEFORCE_NETWORK_FTP_FTP_PROTOCOL_HPP__
5NEFORCE_BEGIN_NAMESPACE__
11struct ftp_exception final : network_exception {
12 explicit ftp_exception(
const char* info =
"FTP Operation Failed.") noexcept :
13 network_exception(info) {}
15 explicit ftp_exception(
const exception& e) :
16 network_exception(e) {}
18 ~ftp_exception()
override =
default;
20 NEFORCE_NODISCARD
const char*
type() const noexcept
override {
return "ftp_exception"; }
23class NEFORCE_API ftp_protocol :
public ip_socket {
25 enum class transfer_mode {
30 enum class passive_mode {
45 NEFORCE_NODISCARD
bool is_success() const noexcept {
return code >= 200 && code < 400; }
46 NEFORCE_NODISCARD
bool is_positive_preliminary() const noexcept {
return code >= 100 && code < 200; }
53 bool peer_verified =
false;
54 bool data_channel =
false;
57 static constexpr size_t kBufferSize = 8192;
60 bool tls_active_ =
false;
62 ssl_context* ssl_ctx_ =
nullptr;
63 bool data_tls_ =
false;
65 char buffer_[kBufferSize]{};
66 size_t buffer_pos_ = 0;
67 size_t buffer_size_ = 0;
69 ftp_protocol() =
default;
71 ftp_protocol(ftp_protocol&& other)
noexcept;
72 ftp_protocol& operator=(ftp_protocol&& other)
noexcept;
74 explicit ftp_protocol(native_handle_type fd) :
78 ~ftp_protocol()
override =
default;
81 ssize_t ctrl_send(
const char* data,
size_t len);
82 ssize_t ctrl_recv(
char* buf,
size_t len);
83 bool ctrl_read_line(
string& out);
85 response read_response();
86 void send_response(
int code,
const string& msg);
87 void send_response(
const response& resp);
95NEFORCE_END_NAMESPACE__
constexpr none_t none
默认空表示
const char * type() const noexcept override
获取异常类型