程序段如下:
//搜索ftp文件
int CTransfer::ftpFindFiles(char * szFind)
{ HINTERNET hInternet,hConnect,hFindFile;
WIN32_FIND_DATA win32_find_data;
int i=0;
BOOL bFound=TRUE;
m_FileCount=0;
BOOL bSuccess ; hInternet=InternetOpen("ftpFindFiles",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,INTERNET_FLAG_ASYNC);
if(hInternet==NULL) return(-1);
hConnect=InternetConnect(hInternet,m_Ftp,INTERNET_DEFAULT_FTP_PORT,m_User,m_Pwd,INTERNET_SERVICE_FTP,0,0);
if(hConnect==NULL) 
{
InternetCloseHandle(hInternet);
m_FileCount=0;
return(-1);
}
bSuccess=FtpSetCurrentDirectory(hConnect,m_Dir);
/*
if (!bSuccess) 
{
m_FileCount=i;
InternetCloseHandle(hConnect);
InternetCloseHandle(hInternet);
return (-1);
}
*/ hFindFile=FtpFindFirstFile(hConnect,szFind,&win32_find_data,INTERNET_FLAG_RESYNCHRONIZE,NULL);
while(i<26){
//&&hFindFile!=NULL&&bFound
if (win32_find_data.dwFileAttributes==FILE_ATTRIBUTE_NORMAL) 
{
//只取文件
*(m_FindedFile+i)=win32_find_data.cFileName;
i++;
}
bFound=InternetFindNextFile(hFindFile,&win32_find_data);
}
m_FileCount=i;
InternetCloseHandle(hConnect);
InternetCloseHandle(hInternet);
return(i);
}
就是遍历ftp当前目录,取得所有文件。但是有3个问题:
1、FtpSetCurrentDirectory(hConnect,m_Dir)始终返回“0”,但是的确可以改变当前目录。
2、bFound=InternetFindNextFile(hFindFile,&win32_find_data)始终返回“0”,但的确可以往下找文件。
3、InternetFindNextFile(hFindFile,&win32_find_data)执行有问题,有的文件没有找出来,有的文件重复找到。我查了很多网上类似的源代码,都是这样写,为什么我的不行?有高手吗?

解决方案 »

  1.   

    对FTP编程不太了解。手头也没有这些函数的资料。不知道这些函数正确执行时,返回值应该是什么
      

  2.   

    FtpSetCurrentDirectory和InternetFindNextFile成功都是应该返回TRUE
      

  3.   

    TRUE indicates success. FALSE indicates failure. To get extended error data, call GetLastError. If the error message indicates that the FTP server denied the request to remove a directory, use InternetGetLastResponseInfo to determine the cause.
      

  4.   

    MSDN have an example ,check this,you can search this article:
    Advanced FTP, or Teaching Fido To Phetch
    Robert Coleridge
    Microsoft Developer Network Technology GroupJuly 29, 1996
      

  5.   

    看看ftp服务器使用的是否是被动模式
      

  6.   

    不用回答了,谢谢你们,我已经解决了。用MFC