123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- #ifndef CURLFTP_H
- #define CURLFTP_H
- #include "curl/curl.h"
- #include <string>
- #include <vector>
- #include <mutex>
- #include "CurlFtpInfo.h"
- class CurlFtp
- {
- public:
- CurlFtp();
- ~CurlFtp();
-
-
- bool setUsernameAndPassword(const std::string& username, const std::string& password);
-
- bool setFtpIPAndPort(const std::string& IP, const int port = 21);
-
- bool setSftpIPAndPort(const std::string& IP, const int port = 22);
-
- void setIgnoreSSLCert(bool isIgnore);
-
- void setCaCertFile(const std::string& caCertFile);
-
- void enableCurlDebug(bool isPrint = false);
-
-
- bool getFileList(std::string dir, std::vector<std::string>& fileList);
-
- bool getDirList(std::string dir, std::vector<std::string>& dirList);
-
- bool isDirExist(const std::string& dir);
-
- bool createDirectory(const std::string& ftpDir);
-
- bool createDirectories(const std::string& ftpDir);
-
- bool downloadFile(const std::string& remoteFile, const std::string& localFile, size_t timeout = 30);
-
- bool downloadToArray(const std::string& remoteFile,std::vector<char>& arrayInfo, size_t timeout = 30);
-
- bool uploadFile(const std::string& localFile, const std::string& remoteFile, size_t timeout = 30, bool isCreateDir = false);
-
- bool uploadData(char* srcData, size_t size, const std::string& remoteFile, size_t timeout = 30, bool isCreateDir = false);
- private:
-
- bool listAll(CURL* curl, std::string dir, std::vector<CF_FileInfo>& fileInfoList);
-
- std::string checkDirPath(const std::string& dir);
-
- std::string checkFilePath(const std::string& file);
-
- bool checkLocalDir(const std::string& localDir);
-
- bool performCurl(CURL* curl);
-
- inline bool resetCurl(CURL* curl);
-
- inline bool setSftp(CURL* curl);
-
- bool checkFtpDirExist(const std::string& dir);
-
- bool checkSftpDirExist(const std::string& dir);
- private:
- std::mutex m_mutexCurl;
- std::string m_currentDir;
- CURL* m_curl = nullptr;
- std::string m_IP;
- int m_port = 21;
- std::string m_ftpUrl;
- std::string m_username;
- std::string m_password;
- bool m_isSftp = false;
- bool m_isIgnoreSSLCert = false;
- bool m_enableCurlDebug = false;
- std::string m_caCertFile;
- };
- #endif
|