app_curlFunc.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef APP_CURLFUNC_H
  2. #define APP_CURLFUNC_H
  3. #include <QObject>
  4. #include <QString>
  5. #include <curl/curl.h>
  6. class CurlFtpUploader : public QObject
  7. {
  8. Q_OBJECT
  9. public:
  10. explicit CurlFtpUploader(QObject *parent = nullptr);
  11. ~CurlFtpUploader();
  12. // 设置 FTP 参数
  13. void setFtpParams(const QString &username,
  14. const QString &password,
  15. const QString &host,
  16. int port,
  17. const QString &remotePath);
  18. // 异步上传文件(非阻塞)
  19. void uploadFileAsync(const QString &localFilePath);
  20. // 补录/重传重载:携带入库时记录的父目录,据此对齐远端归档目录
  21. void uploadFileAsync(const QString &localFilePath, const QString &parentPath);
  22. signals:
  23. void downloadStart(const QString &tips);
  24. void progressChanged(double uploadedPercent, const QString &filePath); // 进度百分比 (0.0 ~ 100.0) 与上传文件路径
  25. void finished(bool success, const QString &error); // 完成信号
  26. void sglProgress(double val,double timeLeft,double speed); //进度信号
  27. private:
  28. // 静态回调函数(供 CURL 调用)
  29. static size_t readCallback(char *buffer, size_t size, size_t nitems, void *userdata);
  30. static int progressCallback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow);
  31. // 内部上传逻辑
  32. void performUpload(const QString &localFilePath);
  33. // 供补录/重传使用,parentPath 为入库时记录的父目录(为空时退回按文件自身父目录推导)
  34. void performUpload(const QString &localFilePath, const QString &parentPath);
  35. // FTP 参数
  36. QString m_username;
  37. QString m_password;
  38. QString m_host;
  39. int m_port;
  40. QString m_remotePath;
  41. QString update_type;
  42. QString m_currentFilePath; // 当前正在上传的文件路径,用于进度信号携带
  43. };
  44. #endif // APP_CURLFUNC_H