CurlFtp.h 1.9 KB

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