#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()); }}
共有 条评论
评论
共有 条评论