CurlFtp.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef CURLFTP_H
  2. #define CURLFTP_H
  3. #include "curl/curl.h"
  4. #include <string>
  5. #include <vector>
  6. #include <mutex>
  7. class CurlFtp
  8. {
  9. public:
  10. CurlFtp();
  11. ~CurlFtp();
  12. /* 列出FTP文件夹 */
  13. static std::string listDir(const std::string &ftpUrl, const std::string &username, const std::string &password);
  14. /* 列出文件夹中的所有文件 */
  15. static bool listFiles(const std::string &ftpUrl, const std::string &username, const std::string &password, std::vector<std::string>& fileList);
  16. /* 检查文件夹是否存在 */
  17. // static bool isDirExists(const std::string &ftpUrl, const std::string &username, const std::string &password);
  18. /* 使用正则表达式提取出文件夹 */
  19. // static bool CurlFtp::extractDirectories(const std::string& responseString);
  20. /* 创建文件夹 */
  21. static bool createDir(const std::string &ftpUrl, const std::string &username, const std::string &password, const std::string &dirName);
  22. /* 设置IP和端口 */
  23. bool setFtpIPAndPort(const std::string& IP, const std::string& port);
  24. /* 设置用户名和密码 */
  25. bool setFtpUsernameAndPassword(const std::string& username, const std::string& password);
  26. /* 列出文件列表 */
  27. bool listAll(std::string dir, std::vector<std::string>& fileList);
  28. private:
  29. std::mutex m_mutexCurl; /* curl互斥锁 */
  30. CURL* m_curl = nullptr; /* curl句柄 */
  31. CURLcode m_res = CURLE_OK; /* 返回值 */
  32. std::string m_responseString; /* */
  33. std::string m_IP; /* IP */
  34. std::string m_port; /* 端口 */
  35. std::string m_ftpUrl; /* ftpUrl */
  36. std::string m_username;
  37. std::string m_password;
  38. std::string m_dirName;
  39. };
  40. #endif /* CURLFTP_H */