91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 246KB
    文件類型: .gz
    金幣: 1
    下載: 0 次
    發布日期: 2021-05-18
  • 語言: C/C++
  • 標簽:

資源簡介

1.使用curl庫實現ftp查詢根目錄下所有文件與目錄,遞歸遍歷所有目錄并下載文件

資源截圖

代碼片段和文件信息

#include?
#include?“SCommon.h“
#include?“SFtpListResp.h“
#include?“SFtpClient.h“
#include?“SBuffer.h“
#include?
#include?
#include?
#include?
#include?
using?namespace?std;
void?DownloadFile(const?std::string&?strRemotePath?const?std::string&?userKey?const?std::string&?strLocalPath);
int?main()
{
????const?char*?url?=?“ftp://10.100.8.22/“;
????const?char*?user_key?=?“admin:111“;
????std::string?strLocalDir=“test/“;
????DownloadFile(url?user_key?strLocalDir);
????return?0;
}


void?DownloadFile(const?std::string&?strRemotePath?const?std::string&?userKey?const?std::string&?strLocalPath)
{
????printf(“remoetepath?=?%s?userkey=?%s?localpath?=?%s\n“?strRemotePath.c_str()?userKey.c_str()?strLocalPath.c_str());
????SBuffer?buffer(1024);
????SFtpClient?ftpclient;
????FTP_STATE?ret?=?ftpclient.ListFile(&buffer?strRemotePath.c_str()?userKey.c_str());
????if(FTP_DOWNLOAD_SUCCESS?!=?ret)
????{
????????printf(“listfile?failed\n“);
????????return;
????}

????SFtpListResp?ftplistResp;
????std::vector??fileInfos;
????int?nRet?=?ftplistResp.parse(std::string(buffer.GetData()buffer.GetSize())fileInfos);
????if(nRet?!=?0)
????{
????????printf(“parse?error\n“);
????????return;
????}
????printf(“fileInfos?size?=?%d\n“?fileInfos.size());
????if(access(strLocalPath.c_str()?0)==-1)
????{
????????mkdir(strLocalPath.c_str()?S_IRWXU|S_IRWXG);
????}

????FTP_OPT?ftp_opt;
????ftp_opt.user_key?=?userKey;
????for(size_t?i=0;?i????{
????????printf(“filename?=?%s?type=%d\n“?fileInfos[i].name.c_str()?fileInfos[i].type);
????????ftp_opt.localfile?=?strLocalPath+fileInfos[i].name;
????????ftp_opt.remotefile?=?strRemotePath+fileInfos[i].name;

????????if(fileInfos[i].type?==?NS_FTP::DIR)
????????{
????????????ftp_opt.remotefile?+=?“/“;
????????????ftp_opt.localfile?+=?“/“;
????????????DownloadFile(ftp_opt.remotefile?userKey?ftp_opt.localfile);
????????????continue;
????????}

????????if(FTP_DOWNLOAD_SUCCESS?==?ftpclient.ftp_download(ftp_opt))
????????????printf(“%s?Download?success.\n“?ftp_opt.remotefile.c_str());
????????else
????????????printf(“%s??Download?failed.\n“?ftp_opt.remotefile.c_str());
????}
}

評論

共有 條評論

相關資源