CmAsterr_ 2022-10-06 21:37 采纳率: 66.7%
浏览 21

CFtpFileFind 遍历 Ftp服务器 目录时的一点问题

在用 CFtpFileFind 写遍历 Ftp服务器 目录的时候,在 DfsServe 函数里面,只有第一次进入该函数的时候 IsFinded 的初值是 true,后来就一直是 false。求各位指教(

#include<afxinet.h>
#include<iostream>
#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)<<" "<<IsFinded << endl;
    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);
}
  • 写回答

1条回答 默认 最新

  • 叶落花枯 2022-10-06 21:49
    关注

    第一次调用 DfsServe 函数,'/' + NowPath 在前面加了 '/' ,后面递归调用的使用又在前面加了 '/' ,多了,路径错了。
    web --> /web
    /web/aaa --> //web/aaa

    评论

报告相同问题?

问题事件

  • 创建了问题 10月6日