Skip to content

Commit

Permalink
NR/FTP: more correct LIST command format autodetection
Browse files Browse the repository at this point in the history
  • Loading branch information
elfmz committed Mar 5, 2024
1 parent 877e856 commit 7ada2e8
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions NetRocks/src/Protocol/FTP/ProtocolFTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ ProtocolFTP::ProtocolFTP(const std::string &protocol, const std::string &host, u
FTPThrowIfBadResponse<ProtocolAuthFailedError>(_str, reply_code, 200, 299);

_cmd.list_ = _conn->ProtocolOptions().GetString("ListCommand", "");
if (_cmd.list_.empty()) {
_str.assign("LIST -la .");
reply_code = _conn->SendRecvResponse(_str);
if (reply_code >= 200 && reply_code < 299) {
_cmd.list_ = "LIST -la";
} else {
_cmd.list_ = "LIST";
}
}

if (_conn->ProtocolOptions().GetInt("MLSDMLST", 1) != 0) {
_str.assign("FEAT");
reply_code = _conn->SendRecvResponse(_str);
Expand Down Expand Up @@ -689,6 +679,20 @@ std::shared_ptr<IDirectoryEnumer> ProtocolFTP::NavigatedDirectoryEnum()
enumer = std::shared_ptr<IDirectoryEnumer>(new FTPDirectoryEnumerMLSD(_conn, data_transport));

} else {
if (_cmd.list_.empty()) {
try {
std::shared_ptr<BaseTransport> tmp_data_transport = _conn->DataCommand("LIST -la");
auto tmp_enumer = std::shared_ptr<IDirectoryEnumer>(new FTPDirectoryEnumerLIST(_conn, tmp_data_transport));
std::string tmp_name, tmp_owner, tmp_group;
FileInformation tmp_file_info;
tmp_enumer->Enum(tmp_name, tmp_owner, tmp_group, tmp_file_info);
_cmd.list_ = "LIST -la";
} catch (std::exception &) {
_cmd.list_ = "LIST";
}
fprintf(stderr, "NR/FTP - list cmd: '%s'\n", _cmd.list_.c_str());
}

std::shared_ptr<BaseTransport> data_transport = _conn->DataCommand(_cmd.list_);
enumer = std::shared_ptr<IDirectoryEnumer>(new FTPDirectoryEnumerLIST(_conn, data_transport));
}
Expand Down

0 comments on commit 7ada2e8

Please sign in to comment.