curl使用ftp获取服务器上指定目录的所有文件集合以及下载
直接编译可用,注意修改测试main函数内的字符串,注释我觉得写的挺详细了,跑不起来的评论区可问
头文件
#ifndef FTP_DOWNLOAD_H
#define FTP_DOWNLOAD_H
#include <iostream>
#include <functional>
#include <memory>
#include <vector>
#include<cstdlib>
#include <ctime>
using namespace std;
using OutPutList = vector<string>;
#define FTPBODY "ftp-list"
struct FtpFile
{
string local;
FILE *stream;
};
class FtpDownloadder
{
public:
/**
* @brief Construct a new Ftp Downloadder object
*
* @param ip
* @param port
* @param username
* @param password
*/
FtpDownloadder(const char *ip,const char *port,const char *username,const char *password);
~FtpDownloadder();
/**
* @brief 获取指定文件夹下所有文件名
*
* @param folderName 指定文件夹名称
* (从登录用户家目录开始算,for example: /home/user/targetFolder , you can give a param with "targetFolder")
* @return OutPutList 该文件夹下的所有文件名集合,包含拓展名
*/
OutPutList getAllItem(const string& folderName);
/**
* @brief 更新本地缓存
*
* @param fileList ftp服务器上的文件集合
* @param remotFolderPath ftp服务器上的文件夹路径
* (从登录用户家目录开始算,for example: /home/user/targetFolder , you can give a param with "targetFolder")
* @param localCacheFolder 本地缓存文件夹
* @return true successful
* @return false faild
*/
bool flashLocalCache(const OutPutList& fileList, const string& remotFolderPath, const string& localCacheFolder);
/**
* @brief 下载文件
*
* @param filePath ftp服务器上的文件路径
*