|
@@ -2,12 +2,19 @@
|
|
|
#include "CurlFtp.h"
|
|
|
#include <regex>
|
|
|
#include <iosfwd>
|
|
|
-#include <filesystem>
|
|
|
#include <fstream>
|
|
|
|
|
|
#include "stdlog.h"
|
|
|
|
|
|
|
|
|
+#if (__cplusplus >= 201703L)
|
|
|
+ #include <filesystem>
|
|
|
+#else
|
|
|
+ #include <QDir>
|
|
|
+ #include <QFileInfo>
|
|
|
+#endif
|
|
|
+
|
|
|
+
|
|
|
#if defined(_WIN32)
|
|
|
|
|
|
#endif
|
|
@@ -896,15 +903,18 @@ bool CurlFtp::uploadFile(const std::string& localFile, const std::string& remote
|
|
|
LOG_ERROR("Url is empty");
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
|
|
|
- if(!std::filesystem::exists(localFile))
|
|
|
+ if(!checkLocalFileExist(localFile))
|
|
|
{
|
|
|
LOG_ERROR("Local file is not exist: " << localFile);
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
|
|
|
std::string remoteFileTmp = checkFilePath(remoteFile);
|
|
|
std::string remoteDirTmp = remoteFileTmp.substr(0, remoteFileTmp.find_last_of("/"));
|
|
|
+
|
|
|
|
|
|
if(!isDirExist(remoteDirTmp))
|
|
|
{
|
|
@@ -920,6 +930,7 @@ bool CurlFtp::uploadFile(const std::string& localFile, const std::string& remote
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
|
|
|
|
|
|
std::string ftpUrl = m_ftpUrl + remoteFileTmp;
|
|
@@ -932,6 +943,7 @@ bool CurlFtp::uploadFile(const std::string& localFile, const std::string& remote
|
|
|
LOG_ERROR("Failed to open local file: " << localFile);
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
|
|
|
|
|
|
ifs.seekg(0, std::ios::end);
|
|
@@ -953,6 +965,7 @@ bool CurlFtp::uploadFile(const std::string& localFile, const std::string& remote
|
|
|
ifs.close();
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
|
|
|
curl_easy_setopt(m_curl, CURLOPT_URL, ftpUrl.c_str());
|
|
|
curl_easy_setopt(m_curl, CURLOPT_PORT, m_port);
|
|
@@ -986,14 +999,17 @@ bool CurlFtp::uploadFile(const std::string& localFile, const std::string& remote
|
|
|
}
|
|
|
|
|
|
curl_easy_setopt(m_curl, CURLOPT_TCP_KEEPALIVE, 1L);
|
|
|
+
|
|
|
|
|
|
bool ret = performCurl(m_curl);
|
|
|
if(!ret)
|
|
|
{
|
|
|
LOG_ERROR("Upload file failed, Url = " << ftpUrl);
|
|
|
}
|
|
|
+
|
|
|
|
|
|
ifs.close();
|
|
|
+
|
|
|
|
|
|
|
|
|
printf("\n");
|
|
@@ -1232,12 +1248,20 @@ bool CurlFtp::checkLocalDir(const std::string& localDir)
|
|
|
std::regex reg(R"([.]*/$)");
|
|
|
std::string localDirTmp = std::regex_replace(localDir, reg, "");
|
|
|
|
|
|
+#if (__cplusplus >= 201703L)
|
|
|
if(std::filesystem::exists(localDirTmp))
|
|
|
+#else
|
|
|
+ if(QDir(localDirTmp.c_str()).exists())
|
|
|
+#endif
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+#if (__cplusplus >= 201703L)
|
|
|
if(!std::filesystem::create_directories(localDirTmp))
|
|
|
+#else
|
|
|
+ if(!QDir().mkpath(localDirTmp.c_str()))
|
|
|
+#endif
|
|
|
{
|
|
|
LOG_ERROR("Failed to create local dir: " << localDirTmp);
|
|
|
return false;
|
|
@@ -1246,6 +1270,40 @@ bool CurlFtp::checkLocalDir(const std::string& localDir)
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+bool CurlFtp::checkLocalDirExist(const std::string& localDir)
|
|
|
+{
|
|
|
+
|
|
|
+ std::regex reg(R"([.]*/$)");
|
|
|
+ std::string localDirTmp = std::regex_replace(localDir, reg, "");
|
|
|
+
|
|
|
+ bool result = false;
|
|
|
+#if (__cplusplus >= 201703L)
|
|
|
+ result = std::filesystem::exists(localDirTmp);
|
|
|
+#else
|
|
|
+ result = QDir(localDirTmp.c_str()).exists();
|
|
|
+#endif
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+bool CurlFtp::checkLocalFileExist(const std::string& localFile)
|
|
|
+{
|
|
|
+
|
|
|
+ std::regex reg(R"([.]*/$)");
|
|
|
+ std::string localDirTmp = std::regex_replace(localFile, reg, "");
|
|
|
+
|
|
|
+ bool result = false;
|
|
|
+#if (__cplusplus >= 201703L)
|
|
|
+ result = std::filesystem::exists(localFile);
|
|
|
+#else
|
|
|
+ result = QFile(localFile.c_str()).exists();
|
|
|
+#endif
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
|
|
|
bool CurlFtp::performCurl(CURL* curl)
|
|
@@ -1368,7 +1426,11 @@ bool CurlFtp::checkFtpDirExist(const std::string& dir)
|
|
|
bool CurlFtp::checkSftpDirExist(const std::string& dir)
|
|
|
{
|
|
|
|
|
|
+#if (__cplusplus >= 201703L)
|
|
|
std::string parentDir = std::filesystem::path(dir).parent_path().string();
|
|
|
+#else
|
|
|
+ std::string parentDir = QFileInfo(QString::fromStdString(dir)).path().toStdString();
|
|
|
+#endif
|
|
|
|
|
|
std::vector<std::string> vecDir;
|
|
|
bool ret = getDirList(parentDir, vecDir);
|
|
@@ -1378,7 +1440,11 @@ bool CurlFtp::checkSftpDirExist(const std::string& dir)
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+#if (__cplusplus >= 201703L)
|
|
|
std::string dirName = std::filesystem::path(dir).filename().string();
|
|
|
+#else
|
|
|
+ std::string dirName = QFileInfo(QString::fromStdString(dir)).fileName().toStdString();
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
bool result = false;
|