在用 CFtpFileFind 写遍历 Ftp服务器 目录的时候,在 DfsServe
函数里面,只有第一次进入该函数的时候 IsFinded
的初值是 true
,后来就一直是 false
。求各位指教(
#include
#include
#include"atlconv.h"
using namespace std;
CInternetSession InternetSession;
CFtpConnection* FtpConnection;
void DfsServe( CString NowPath){
USES_CONVERSION;
CFtpFileFind Find(FtpConnection);
bool IsFinded = Find.FindFile('/'+NowPath);
// cout << T2A('/'+NowPath)<<" "<
while (IsFinded){
IsFinded = Find.FindNextFile();
if (Find.IsDots())continue;//若是'.'或'..'则不继续.
CString NewPath; NewPath.Empty();
NewPath = NowPath + '/' + Find.GetFileName().GetBuffer();
if (Find.IsDirectory()) DfsServe(NewPath);
else cout << T2A(NewPath) << endl;//输出文件位置.
}
Find.Close();
}
int main(){
FtpConnection = InternetSession.GetFtpConnection(L"43.226.74.11", L"ftp6286910",L"密码不可见...", 21, true);
//密码做了特殊处理,防止别有用心之人.
if (FtpConnection != NULL)cout << "成功连接FTP服务器!!\n";
DfsServe("web");
while (1);
}
第一次调用 DfsServe 函数,'/' + NowPath 在前面加了 '/' ,后面递归调用的使用又在前面加了 '/' ,多了,路径错了。
web --> /web
/web/aaa --> //web/aaa