-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathftp_codes.cpp
More file actions
44 lines (37 loc) · 1.93 KB
/
ftp_codes.cpp
File metadata and controls
44 lines (37 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "ftp_codes.h"
#include <sstream>
namespace ftp {
std::string default_text(Code code) {
switch (code) {
case Code::OpeningDataBin: return "File status okay; about to open data connection.";
case Code::OK: return "Command okay.";
case Code::SystemReady: return "Service ready for new user.";
case Code::Goodbye: return "Goodbye.";
case Code::LoggedIn: return "User logged in, proceed.";
case Code::FileActionOK: return "Requested file action okay, completed.";
case Code::ClosingData: return "Closing data connection. Requested file action successful.";
case Code::PathCreated: return "\"/\" is the current directory.";
case Code::NeedMore: return "Requested file action pending further information.";
case Code::CannotOpenData: return "Can't open data connection.";
case Code::LocalError: return "Requested action aborted: local error in processing.";
case Code::SyntaxError: return "Syntax error in parameters or arguments.";
case Code::NotImplemented: return "Command not implemented.";
case Code::NotLoggedIn: return "Not logged in.";
case Code::FileUnavailable: return "Requested action not taken. File unavailable.";
default: return "OK";
}
}
std::string format_reply(Code code, std::string_view text) {
std::ostringstream oss;
oss << static_cast<int>(code) << ' ' << (text.empty() ? default_text(code) : std::string(text));
return oss.str();
}
std::string format_pasv_reply(std::string_view ip_tuple, int p1, int p2) {
std::ostringstream oss;
oss << "227 Entering Passive Mode (" << ip_tuple << "," << p1 << "," << p2 << ").";
// TODO:
// FOR TESTING ONLY - REMOVE ME
oss << " [DEBUG TEST PORT = " << (p1 * 256 + p2) << "]"; // --- IGNORE ---
return oss.str();
}
} // namespace ftp