|
@@ -5,12 +5,8 @@
|
|
|
#include <filesystem>
|
|
|
#include <fstream>
|
|
|
|
|
|
-
|
|
|
-#include "spdlog/spdlog.h"
|
|
|
+#include "stdlog.h"
|
|
|
|
|
|
-#ifndef SPDLOG_ACTIVE_LEVEL
|
|
|
-#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG
|
|
|
-#endif
|
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
|
@@ -286,7 +282,7 @@ static int progress_callback(void *clientp,
|
|
|
curl_off_t ultotal,
|
|
|
curl_off_t ulnow)
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
if(dltotal == 0 && ultotal == 0)
|
|
|
{
|
|
|
dCount = 0;
|
|
@@ -297,7 +293,7 @@ static int progress_callback(void *clientp,
|
|
|
}
|
|
|
std::chrono::system_clock::time_point nowTime = std::chrono::system_clock::now();
|
|
|
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(nowTime - lastTime).count();
|
|
|
-
|
|
|
+
|
|
|
if((duration < 1000) && ((dltotal != dlnow) || (ultotal != ulnow)))
|
|
|
{
|
|
|
return 0;
|
|
@@ -346,7 +342,7 @@ const std::regex parseRegSpace(R"(( )+)");
|
|
|
* (文件类型) ... (文件大小,$5) ... (文件名)
|
|
|
*/
|
|
|
const std::regex parseReg1(R"(^([^ ]+) (\d*) (\w*) (\w*) (\d*) (.*) ([^ ]+)$)");
|
|
|
-
|
|
|
+
|
|
|
|
|
|
const std::regex parseReg2(R"(\n)");
|
|
|
|
|
@@ -370,14 +366,14 @@ static bool parseFileInfo(const std::string& strSrc, std::vector<CF_FileInfo>& f
|
|
|
std::string str2 = strSrc;
|
|
|
#endif
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -393,7 +389,7 @@ static bool parseFileInfo(const std::string& strSrc, std::vector<CF_FileInfo>& f
|
|
|
{
|
|
|
|
|
|
auto line = std::regex_replace(it2->str(), parseRegSpace, " ");
|
|
|
-
|
|
|
+
|
|
|
CF_FileInfo fi;
|
|
|
|
|
|
std::string strFileType = std::regex_replace(line, parseReg1, "$1");
|
|
@@ -458,7 +454,7 @@ bool CurlFtp::setFtpIPAndPort(const std::string& IP, const int port)
|
|
|
m_IP = IP;
|
|
|
m_port = port;
|
|
|
m_ftpUrl = "ftp://" + m_IP + ":" + std::to_string(m_port);
|
|
|
- SPDLOG_INFO("Set ftpUrl = {}", m_ftpUrl);
|
|
|
+ LOG_INFO("Set ftpUrl = " << m_ftpUrl);
|
|
|
m_isSftp = false;
|
|
|
return true;
|
|
|
}
|
|
@@ -469,7 +465,7 @@ bool CurlFtp::setSftpIPAndPort(const std::string& IP, const int port)
|
|
|
m_IP = IP;
|
|
|
m_port = port;
|
|
|
m_ftpUrl = "sftp://" + m_IP + ":" + std::to_string(m_port);
|
|
|
- SPDLOG_INFO("Set sftpUrl = {}", m_ftpUrl);
|
|
|
+ LOG_INFO("Set sftpUrl = " << m_ftpUrl);
|
|
|
m_isSftp = true;
|
|
|
return true;
|
|
|
}
|
|
@@ -498,7 +494,7 @@ bool CurlFtp::getFileList(std::string dir, std::vector<std::string>& fileList)
|
|
|
{
|
|
|
if(m_IP.empty())
|
|
|
{
|
|
|
- SPDLOG_WARN("IP or port is empty");
|
|
|
+ LOG_WARN("IP or port is empty");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -508,7 +504,7 @@ bool CurlFtp::getFileList(std::string dir, std::vector<std::string>& fileList)
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
resetCurl(m_curl);
|
|
@@ -518,7 +514,7 @@ bool CurlFtp::getFileList(std::string dir, std::vector<std::string>& fileList)
|
|
|
listAll(m_curl, dirTmp, listInfo);
|
|
|
for(const CF_FileInfo& fi : listInfo)
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
if(fi.type == CF_FileType::FILE)
|
|
|
{
|
|
|
fileList.push_back(fi.name);
|
|
@@ -535,7 +531,7 @@ bool CurlFtp::getDirList(std::string dir, std::vector<std::string>& dirList)
|
|
|
{
|
|
|
if(m_IP.empty())
|
|
|
{
|
|
|
- SPDLOG_WARN("IP or port is empty");
|
|
|
+ LOG_WARN("IP or port is empty");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -545,7 +541,7 @@ bool CurlFtp::getDirList(std::string dir, std::vector<std::string>& dirList)
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
resetCurl(m_curl);
|
|
@@ -555,7 +551,7 @@ bool CurlFtp::getDirList(std::string dir, std::vector<std::string>& dirList)
|
|
|
listAll(m_curl, dirTmp, listInfo);
|
|
|
for(const CF_FileInfo& fi : listInfo)
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
if(fi.type == CF_FileType::DIR)
|
|
|
{
|
|
|
dirList.push_back(fi.name);
|
|
@@ -578,10 +574,10 @@ bool CurlFtp::getDirList(std::string dir, std::vector<std::string>& dirList)
|
|
|
*/
|
|
|
bool CurlFtp::isDirExist(const std::string& dir)
|
|
|
{
|
|
|
- SPDLOG_DEBUG("Check remote dir: {}", dir);
|
|
|
+ LOG_DEBUG("Check remote dir:" << dir);
|
|
|
if(m_ftpUrl.empty())
|
|
|
{
|
|
|
- SPDLOG_ERROR("ftpUrl is empty");
|
|
|
+ LOG_ERROR("ftpUrl is empty");
|
|
|
return false;
|
|
|
}
|
|
|
if(dir == "/")
|
|
@@ -611,7 +607,7 @@ bool CurlFtp::createDirectory(const std::string& ftpDir)
|
|
|
{
|
|
|
if(m_ftpUrl.empty())
|
|
|
{
|
|
|
- SPDLOG_ERROR("ftpUrl is empty");
|
|
|
+ LOG_ERROR("ftpUrl is empty");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -626,7 +622,7 @@ bool CurlFtp::createDirectory(const std::string& ftpDir)
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
resetCurl(m_curl);
|
|
@@ -665,12 +661,12 @@ bool CurlFtp::createDirectory(const std::string& ftpDir)
|
|
|
|
|
|
|
|
|
|
|
|
- SPDLOG_DEBUG("Create remote dir: {}", dirTmp);
|
|
|
+ LOG_DEBUG("Create remote dir: " << dirTmp);
|
|
|
|
|
|
bool ret = performCurl(m_curl);
|
|
|
if(!ret)
|
|
|
{
|
|
|
- SPDLOG_ERROR("Failed to create remote Dir");
|
|
|
+ LOG_ERROR("Failed to create remote Dir");
|
|
|
}
|
|
|
|
|
|
|
|
@@ -708,10 +704,10 @@ bool CurlFtp::createDirectories(const std::string& ftpDir)
|
|
|
|
|
|
for(const std::string& dir : dirList)
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
if(!createDirectory(dir))
|
|
|
{
|
|
|
- SPDLOG_ERROR("Failed to create dir: {}", dir);
|
|
|
+ LOG_ERROR("Failed to create dir: " << dir);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
@@ -735,7 +731,7 @@ bool CurlFtp::downloadFile(const std::string& remoteFile, const std::string& loc
|
|
|
{
|
|
|
if(m_ftpUrl.empty())
|
|
|
{
|
|
|
- SPDLOG_ERROR("ftpUrl is empty");
|
|
|
+ LOG_ERROR("ftpUrl is empty");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -747,7 +743,7 @@ bool CurlFtp::downloadFile(const std::string& remoteFile, const std::string& loc
|
|
|
std::string localDirTmp = localFile.substr(0, localFile.find_last_of("/"));
|
|
|
if(!checkLocalDir(localDirTmp))
|
|
|
{
|
|
|
- SPDLOG_ERROR("Failed to create local dir: {}", localDirTmp);
|
|
|
+ LOG_ERROR("Failed to create local dir: " << localDirTmp);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -755,7 +751,7 @@ bool CurlFtp::downloadFile(const std::string& remoteFile, const std::string& loc
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
resetCurl(m_curl);
|
|
@@ -797,7 +793,9 @@ bool CurlFtp::downloadFile(const std::string& remoteFile, const std::string& loc
|
|
|
bool ret = performCurl(m_curl);
|
|
|
if(!ret)
|
|
|
{
|
|
|
- SPDLOG_ERROR("Failed to get file list, Url = {}", ftpUrl);
|
|
|
+ std::stringstream ss;
|
|
|
+ ss << "Failed to download file: " << ftpUrl;
|
|
|
+ LOG_ERROR("Failed to get file list, Url = " << ftpUrl);
|
|
|
|
|
|
ofs.close();
|
|
|
std::remove(localFile.c_str());
|
|
@@ -819,7 +817,7 @@ bool CurlFtp::downloadToArray(const std::string& remoteFile, std::vector<char>&
|
|
|
{
|
|
|
if(m_ftpUrl.empty())
|
|
|
{
|
|
|
- SPDLOG_ERROR("ftpUrl is empty");
|
|
|
+ LOG_ERROR("ftpUrl is empty");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -831,7 +829,7 @@ bool CurlFtp::downloadToArray(const std::string& remoteFile, std::vector<char>&
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
resetCurl(m_curl);
|
|
@@ -870,7 +868,7 @@ bool CurlFtp::downloadToArray(const std::string& remoteFile, std::vector<char>&
|
|
|
bool ret = performCurl(m_curl);
|
|
|
if(!ret)
|
|
|
{
|
|
|
- SPDLOG_ERROR("Failed to get file list, Url = {}", ftpUrl);
|
|
|
+ LOG_ERROR("Failed to get file list, Url = " << ftpUrl);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -895,13 +893,13 @@ bool CurlFtp::uploadFile(const std::string& localFile, const std::string& remote
|
|
|
{
|
|
|
if(m_ftpUrl.empty())
|
|
|
{
|
|
|
- SPDLOG_ERROR("Url is empty");
|
|
|
+ LOG_ERROR("Url is empty");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if(!std::filesystem::exists(localFile))
|
|
|
{
|
|
|
- SPDLOG_ERROR("Local file is not exist: {}", localFile);
|
|
|
+ LOG_ERROR("Local file is not exist: " << localFile);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -914,11 +912,11 @@ bool CurlFtp::uploadFile(const std::string& localFile, const std::string& remote
|
|
|
{
|
|
|
if(!createDirectories(remoteDirTmp))
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
return false;
|
|
|
}
|
|
|
}else {
|
|
|
- SPDLOG_ERROR("Remote dir is not exist: {}", remoteDirTmp);
|
|
|
+ LOG_ERROR("Remote dir is not exist: " << remoteDirTmp);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
@@ -931,7 +929,7 @@ bool CurlFtp::uploadFile(const std::string& localFile, const std::string& remote
|
|
|
ifs.open(localFile, std::ios::in | std::ios::binary);
|
|
|
if(!ifs.is_open())
|
|
|
{
|
|
|
- SPDLOG_ERROR("Failed to open local file: {}", localFile);
|
|
|
+ LOG_ERROR("Failed to open local file: " << localFile);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -940,13 +938,13 @@ bool CurlFtp::uploadFile(const std::string& localFile, const std::string& remote
|
|
|
auto fileSize = ifs.tellg();
|
|
|
|
|
|
ifs.seekg(0, std::ios::beg);
|
|
|
- SPDLOG_DEBUG("File size: {}", (long)fileSize);
|
|
|
+ LOG_DEBUG("File size: " << (long)fileSize);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -992,7 +990,7 @@ bool CurlFtp::uploadFile(const std::string& localFile, const std::string& remote
|
|
|
bool ret = performCurl(m_curl);
|
|
|
if(!ret)
|
|
|
{
|
|
|
- SPDLOG_ERROR("Upload file failed, Url = {}", ftpUrl);
|
|
|
+ LOG_ERROR("Upload file failed, Url = " << ftpUrl);
|
|
|
}
|
|
|
|
|
|
ifs.close();
|
|
@@ -1020,7 +1018,7 @@ bool CurlFtp::uploadData(char* srcData, size_t size, const std::string& remoteFi
|
|
|
{
|
|
|
if(m_ftpUrl.empty())
|
|
|
{
|
|
|
- SPDLOG_ERROR("Url is empty");
|
|
|
+ LOG_ERROR("Url is empty");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -1039,23 +1037,23 @@ bool CurlFtp::uploadData(char* srcData, size_t size, const std::string& remoteFi
|
|
|
{
|
|
|
if(!createDirectories(remoteDirTmp))
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
return false;
|
|
|
}
|
|
|
}else {
|
|
|
- SPDLOG_ERROR("Remote dir is not exist: {}", remoteDirTmp);
|
|
|
+ LOG_ERROR("Remote dir is not exist: " << remoteDirTmp);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
std::string ftpUrl = m_ftpUrl + remoteFileTmp;
|
|
|
- SPDLOG_DEBUG("Data size: {}", arrayInfo.size);
|
|
|
+ LOG_DEBUG("Data size: " << arrayInfo.size);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
if(!resetCurl(m_curl))
|
|
@@ -1100,7 +1098,7 @@ bool CurlFtp::uploadData(char* srcData, size_t size, const std::string& remoteFi
|
|
|
bool ret = performCurl(m_curl);
|
|
|
if(!ret)
|
|
|
{
|
|
|
- SPDLOG_ERROR("Upload file failed, Url = {}", ftpUrl);
|
|
|
+ LOG_ERROR("Upload file failed, Url = " << ftpUrl);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -1125,7 +1123,7 @@ bool CurlFtp::listAll(CURL* curl, std::string dir, std::vector<CF_FileInfo>& fil
|
|
|
{
|
|
|
if(m_IP.empty())
|
|
|
{
|
|
|
- SPDLOG_ERROR("IP is empty");
|
|
|
+ LOG_ERROR("IP is empty");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -1162,7 +1160,7 @@ bool CurlFtp::listAll(CURL* curl, std::string dir, std::vector<CF_FileInfo>& fil
|
|
|
bool ret = performCurl(curl);
|
|
|
if(!ret)
|
|
|
{
|
|
|
- SPDLOG_ERROR("Failed to get file listUrl = {}", ftpUrl);
|
|
|
+ LOG_ERROR("Failed to get file listUrl = " << ftpUrl);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -1202,7 +1200,7 @@ std::string CurlFtp::checkFilePath(const std::string& file)
|
|
|
std::regex reg2(R"([.]*/$)");
|
|
|
if(std::regex_match(dirTmp, reg2))
|
|
|
{
|
|
|
- SPDLOG_ERROR("File path is not correct, end with '/'");
|
|
|
+ LOG_ERROR("File path is not correct, end with '/'");
|
|
|
return std::string();
|
|
|
}
|
|
|
|
|
@@ -1241,7 +1239,7 @@ bool CurlFtp::checkLocalDir(const std::string& localDir)
|
|
|
|
|
|
if(!std::filesystem::create_directories(localDirTmp))
|
|
|
{
|
|
|
- SPDLOG_ERROR("Failed to create local dir: {}", localDirTmp);
|
|
|
+ LOG_ERROR("Failed to create local dir: " << localDirTmp);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -1262,15 +1260,15 @@ bool CurlFtp::performCurl(CURL* curl)
|
|
|
}
|
|
|
else if (res == CURLE_LOGIN_DENIED)
|
|
|
{
|
|
|
- SPDLOG_ERROR("Login failed, error code: {} ,{}", (int)res, curl_easy_strerror(res));
|
|
|
+ LOG_ERROR("Login failed, error code: " << (int)res << ", " << curl_easy_strerror(res));
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_USERNAME, m_username.c_str());
|
|
|
curl_easy_setopt(curl, CURLOPT_PASSWORD, m_password.c_str());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- SPDLOG_ERROR("Perform curl failed, error code: {} ,{}", (int)res, curl_easy_strerror(res));
|
|
|
- SPDLOG_ERROR("Retry times: {}", 4 - retry);
|
|
|
+ LOG_ERROR("Perform curl failed, error code: " << (int)res << ", " << curl_easy_strerror(res));
|
|
|
+ LOG_ERROR("Retry times: " << (4 - retry));
|
|
|
}
|
|
|
retry--;
|
|
|
}
|
|
@@ -1286,7 +1284,7 @@ bool CurlFtp::resetCurl(CURL* curl)
|
|
|
m_curl = curl_easy_init();
|
|
|
if(m_curl == nullptr)
|
|
|
{
|
|
|
- SPDLOG_ERROR("curl init failed !");
|
|
|
+ LOG_ERROR("curl init failed !");
|
|
|
return false;
|
|
|
}
|
|
|
}else {
|
|
@@ -1359,10 +1357,10 @@ bool CurlFtp::checkFtpDirExist(const std::string& dir)
|
|
|
result = true;
|
|
|
} else
|
|
|
{
|
|
|
- SPDLOG_ERROR("Check remote dir error, error code: {} ,{}", (int)res, curl_easy_strerror(res));
|
|
|
+ LOG_ERROR("Check remote dir error, error code: " << (int)res << ", " << curl_easy_strerror(res));
|
|
|
result = false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -1371,17 +1369,17 @@ bool CurlFtp::checkSftpDirExist(const std::string& dir)
|
|
|
{
|
|
|
|
|
|
std::string parentDir = std::filesystem::path(dir).parent_path().string();
|
|
|
-
|
|
|
+
|
|
|
std::vector<std::string> vecDir;
|
|
|
bool ret = getDirList(parentDir, vecDir);
|
|
|
if(!ret)
|
|
|
{
|
|
|
- SPDLOG_ERROR("Failed to check sftp dir: {}", dir);
|
|
|
+ LOG_ERROR("Failed to check sftp dir: " << dir);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
std::string dirName = std::filesystem::path(dir).filename().string();
|
|
|
-
|
|
|
+
|
|
|
|
|
|
bool result = false;
|
|
|
for(const std::string& str : vecDir)
|