Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A suggestion for creating multi-level directories. #2

Open
pioneer2023 opened this issue May 15, 2022 · 0 comments
Open

A suggestion for creating multi-level directories. #2

pioneer2023 opened this issue May 15, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@pioneer2023
Copy link

bool client::mkdir(const string& directory_name) {
try {
if (!is_open()) {
throw ftp_exception("Connection is not open.");
}

std::filesystem::path path(directory_name);
auto ss = path.string();
if (ss == "")return false;
try {
  if (ls(ss)) return true;
} catch (...) {
}

std::vector<string> sub_dirs;
for (auto& sub : path) {
  sub_dirs.push_back(sub.string());
}

string to_dir;

if (sub_dirs.empty()) {
  throw ftp_exception("MKD empty sub_dirs.");
}
reply_t reply;
for (auto i = 0; i < sub_dirs.size(); i++) {
  auto s = sub_dirs[i];
  if (s == "") break;
  to_dir += s;
  to_dir += "/";

  reply = send_command("MKD " + to_dir);
}
if (reply.status_code == 550) return true;
return reply.is_positive();

} catch (const connection_exception& ex) {
reset_connection();
throw ftp_exception(ex);
}
}

@deniskovalchuk deniskovalchuk added the enhancement New feature or request label Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants