FILETIME fileTime;
CString str,szFile,szFtpInfo;
WIN32_FIND_DATA findData;
HINTERNET hFind;
HINTERNET hInetSession=InternetOpen(szAppName,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
szFtpInfo="正在连接";
szFtpInfo+=szFtpName;
szFtpInfo+="服务器";
pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
HINTERNET hFtpConn=InternetConnect(hInetSession,szFtpName,nPort,
szFtpUser,szFtpPassword,INTERNET_SERVICE_FTP,INTERNET_FLAG_PASSIVE,0);
if(!hFtpConn)
{
szFtpInfo=szFtpName;
szFtpInfo+="服务器未接上";
pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
InternetCloseHandle(hInetSession);
::Sleep(10);
return 0L;
}
szFtpInfo=szFtpName;
szFtpInfo+="服务器已连上,用户";
szFtpInfo+=szFtpUser;
szFtpInfo+="登录成功";
pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
DWORD dwLength=MAX_PATH;
if(szFtpDirectory!=0)
FtpSetCurrentDirectory(hFtpConn,szFtpDirectory);
FtpGetCurrentDirectory(hFtpConn,szFtpDirectory,&dwLength);
::PostMessage(pServView->m_hWnd,WM_SETDIRECTORYDISPLAY,0,0);
szFtpInfo="正在查找文件";
if(!(hFind=FtpFindFirstFile(hFtpConn,_T("*"),&findData,0,0)))
{
if (GetLastError()  == ERROR_NO_MORE_FILES) 
{
AfxMessageBox("目录为空,没有多余的内容");
goto end;
}
else
{
szFtpInfo="文件查找出错,退回,请查明原因";
pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
goto end;
}
}
do{
szFile=findData.cFileName;
strcpy(pInfo->szFileName,szFile);
fileTime=findData.ftLastWriteTime;
CTime time=CTime(fileTime);
CString str=time.Format("%x");
strcpy(pInfo->szFileDate,str);
if(findData.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY)
{
strcpy(pInfo->szFileSize,"");
pInfo->nType=DIRECTORYICON;
}
else
{
DWORD i=findData.nFileSizeLow;
if(i>1024)
{
str.Format("%ld",i/1024);
str+="KB";
}
else
str.Format("%ld",i);
strcpy(pInfo->szFileSize,str);
pInfo->nType=FILEICON;
}
::SendMessage(pServView->m_hWnd,WM_SETFILE,(WPARAM)pInfo,(LPARAM)SERVFILE);

}while(InternetFindNextFile(hFind,&findData));

::SendMessage(pServView->m_hWnd,WM_SETREDRAWFLAG,0,0);
InternetCloseHandle(hFind);
end:
szFtpInfo="查找文件结束";
pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
::Sleep(10);
delete pInfo;
InternetCloseHandle(hFtpConn);
InternetCloseHandle(hInetSession);