|
@@ -1317,19 +1317,25 @@ bool CurlFtp::setSftp(CURL* curl)
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-/* 检查FTP文件夹是否存在 */
|
|
|
+/**
|
|
|
+ * @brief 检查FTP文件夹是否存在,注意,传入的文件夹最后一定要带/,否则会检查的是文件
|
|
|
+ *
|
|
|
+ * @param dir
|
|
|
+ * @return true
|
|
|
+ * @return false
|
|
|
+ */
|
|
|
bool CurlFtp::checkFtpDirExist(const std::string& dir)
|
|
|
{
|
|
|
/* 检查传入的文件夹 */
|
|
|
auto dirTmp = checkDirPath(dir);
|
|
|
resetCurl(m_curl);
|
|
|
- std::string ftpUrl = m_ftpUrl + dir;
|
|
|
+ std::string ftpUrl = m_ftpUrl + dirTmp;
|
|
|
curl_easy_setopt(m_curl, CURLOPT_URL, ftpUrl.c_str());
|
|
|
curl_easy_setopt(m_curl, CURLOPT_USERNAME, m_username.c_str());
|
|
|
curl_easy_setopt(m_curl, CURLOPT_PASSWORD, m_password.c_str());
|
|
|
/* 获取文件夹是否存在,不需要接收文件 */
|
|
|
curl_easy_setopt(m_curl, CURLOPT_NOBODY, 1L);
|
|
|
- curl_easy_setopt(m_curl, CURLOPT_HEADER, 1L);
|
|
|
+ // curl_easy_setopt(m_curl, CURLOPT_HEADER, 1L);
|
|
|
|
|
|
/* 设置SFTP */
|
|
|
setSftp(m_curl);
|
|
@@ -1348,23 +1354,15 @@ bool CurlFtp::checkFtpDirExist(const std::string& dir)
|
|
|
{
|
|
|
result = false;
|
|
|
}
|
|
|
- else if(res != CURLE_OK)
|
|
|
+ else if(res == CURLE_OK)
|
|
|
{
|
|
|
- // SPDLOG_ERROR("Check remote dir error, error code: {} ,{}", (int)res, curl_easy_strerror(res));
|
|
|
- result = false;
|
|
|
- }
|
|
|
- else
|
|
|
+ result = true;
|
|
|
+ } else
|
|
|
{
|
|
|
- /* sftp即使远程文件夹不存在也会返回OK,这里使用http进行检查 */
|
|
|
- // long response_code = -1;
|
|
|
- // res = curl_easy_getinfo(m_curl, CURLINFO_HTTP_CONNECTCODE, &response_code);
|
|
|
- // if((res == CURLE_OK) && (response_code == 0))
|
|
|
- // {
|
|
|
- // SPDLOG_ERROR("Remote directory not found: {}", dir);
|
|
|
- // result = false;
|
|
|
- // }
|
|
|
- // SPDLOG_DEBUG("response_code: {}", response_code);
|
|
|
+ SPDLOG_ERROR("Check remote dir error, error code: {} ,{}", (int)res, curl_easy_strerror(res));
|
|
|
+ result = false;
|
|
|
}
|
|
|
+ // SPDLOG_DEBUG("Check remote dir: {}, res: {}", dir, (int)res);
|
|
|
return result;
|
|
|
}
|
|
|
|