From 7ada2e81ec30c7abbfb3f10b01df310ff2e6cb3e Mon Sep 17 00:00:00 2001 From: elfmz Date: Tue, 5 Mar 2024 10:34:40 +0300 Subject: [PATCH] NR/FTP: more correct LIST command format autodetection --- NetRocks/src/Protocol/FTP/ProtocolFTP.cpp | 24 +++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/NetRocks/src/Protocol/FTP/ProtocolFTP.cpp b/NetRocks/src/Protocol/FTP/ProtocolFTP.cpp index 5260b44ef..0d94bbe5f 100644 --- a/NetRocks/src/Protocol/FTP/ProtocolFTP.cpp +++ b/NetRocks/src/Protocol/FTP/ProtocolFTP.cpp @@ -36,16 +36,6 @@ ProtocolFTP::ProtocolFTP(const std::string &protocol, const std::string &host, u FTPThrowIfBadResponse(_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); @@ -689,6 +679,20 @@ std::shared_ptr ProtocolFTP::NavigatedDirectoryEnum() enumer = std::shared_ptr(new FTPDirectoryEnumerMLSD(_conn, data_transport)); } else { + if (_cmd.list_.empty()) { + try { + std::shared_ptr tmp_data_transport = _conn->DataCommand("LIST -la"); + auto tmp_enumer = std::shared_ptr(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 data_transport = _conn->DataCommand(_cmd.list_); enumer = std::shared_ptr(new FTPDirectoryEnumerLIST(_conn, data_transport)); }