1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #ifndef CURLFTP_H
- #define CURLFTP_H
- #include "curl/curl.h"
- #include <string>
- #include <vector>
- #include <mutex>
- struct CF_FileInfo;
- class CurlFtp
- {
- public:
- CurlFtp();
- ~CurlFtp();
- /* 列出FTP文件夹 */
- static std::string listDir(const std::string &ftpUrl, const std::string &username, const std::string &password);
- /* 列出文件夹中的所有文件 */
- static bool listFiles(const std::string &ftpUrl, const std::string &username, const std::string &password, std::vector<std::string>& fileList);
- /* 检查文件夹是否存在 */
- // static bool isDirExists(const std::string &ftpUrl, const std::string &username, const std::string &password);
- /* 使用正则表达式提取出文件夹 */
- // static bool CurlFtp::extractDirectories(const std::string& responseString);
- /* 创建文件夹 */
- static bool createDir(const std::string &ftpUrl, const std::string &username, const std::string &password, const std::string &dirName);
- /* 设置IP和端口 */
- bool setFtpIPAndPort(const std::string& IP, const std::string& port);
- /* 设置用户名和密码 */
- bool setFtpUsernameAndPassword(const std::string& username, const std::string& password);
- /* 列出文件列表 */
- bool getFileList(std::string dir, std::vector<std::string>& fileList);
- private:
- /* 列出所有内容 */
- bool listAll(std::string dir, std::vector<CF_FileInfo>& fileList);
- private:
- std::mutex m_mutexCurl; /* curl互斥锁 */
- CURL* m_curl = nullptr; /* curl句柄 */
- CURLcode m_res = CURLE_OK; /* 返回值 */
- std::string m_responseString; /* */
- std::string m_IP; /* IP */
- std::string m_port; /* 端口 */
- std::string m_ftpUrl; /* ftpUrl */
- std::string m_username;
- std::string m_password;
- std::string m_dirName;
- };
- #endif /* CURLFTP_H */
|