Skip to content

A suggestion for creating multi-level directories. #2

@AnyPioneer

Description

@AnyPioneer

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);
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions