Problem for Download directory FTP VC++ code
-
Please look at my code given below. I am trying to download the one folder from one site using FTP I have written the code for Download directory which calls itself recursivly and I am closing and opening the connetion eac time. But the problem is it downloads only first two folders completly but it could not find the third folder or file though it is there. FindNextFile function returns false after downloading second folder. Please help me for this.. Here is the code for Download Directory BOOL CFTPUpDwnldManager::DownloadDirectory(CString strSrcDirPth, CString strTrgfDirPath) { BOOL bRetVal = FALSE; theApp.WriteFTPlog("Src Directory:" + strSrcDirPth); theApp.WriteFTPlog("Trg Directory:" + strTrgfDirPath); if(strSrcDirPth.IsEmpty() || strTrgfDirPath.IsEmpty()) { return bRetVal; } // assum that *.* is not apped in src and trg path CString strSrcDirPth1 = strSrcDirPth; int index = strSrcDirPth1.ReverseFind('//'); int indx= strSrcDirPth1.GetLength() - index; CString strSrcDirPth2 = strSrcDirPth1.Right(indx); CString RemoteDir=strSrcDirPth; CString dirpath=strTrgfDirPath + strSrcDirPth2; CreateDirectory(dirpath,NULL); CString LocalDir = dirpath; CFTPUpDwnldManager *pCFTPUpDMngr = (CFTPUpDwnldManager *)lParam; if(NULL == pCFTPUpDMngr) { return bRetVal; } CFTPManager *pFTPManager = (CFTPManager *)lParam; if(NULL == pFTPManager) { return bRetVal; } CNSInternetSession* pInternetSession = pFTPManager->GetInternetSessionPtr(); if(NULL == pInternetSession) { return bRetVal; } pCFTPUpDMngr->CloseFTPConnection(); if(-1 == pCFTPUpDMngr->GetFTPConnection()) { return bRetVal; } CFtpFileFind fileFind(pFtpConnection,0); CString strFindFilePath = RemoteDir + "/*.*"; BOOL bContinue = fileFind.FindFile(strFindFilePath) ; DWORD dw = GetLastError(); if (!bContinue) { // the directory is empty; just close up and return. fileFind.Close(); return bRetVal; } while (bContinue) { bContinue = fileFind.FindNextFile(); DWORD dw = GetLastError(); CString tempDirName = fileFind.GetFileName(); CString tempDirPath = fileFind.GetFilePath(); CString tempFileUrl= fileFind.GetFileURL(); if(fileFind.IsDots()) { continue; } if (fileFind.IsDirectory()) { CString NewSrcDir = RemoteDir + "/" + tempDirName; //CString NewTrgDIr = LocalDir + "/" + tempDirName; CString NewTrgDir
-
Please look at my code given below. I am trying to download the one folder from one site using FTP I have written the code for Download directory which calls itself recursivly and I am closing and opening the connetion eac time. But the problem is it downloads only first two folders completly but it could not find the third folder or file though it is there. FindNextFile function returns false after downloading second folder. Please help me for this.. Here is the code for Download Directory BOOL CFTPUpDwnldManager::DownloadDirectory(CString strSrcDirPth, CString strTrgfDirPath) { BOOL bRetVal = FALSE; theApp.WriteFTPlog("Src Directory:" + strSrcDirPth); theApp.WriteFTPlog("Trg Directory:" + strTrgfDirPath); if(strSrcDirPth.IsEmpty() || strTrgfDirPath.IsEmpty()) { return bRetVal; } // assum that *.* is not apped in src and trg path CString strSrcDirPth1 = strSrcDirPth; int index = strSrcDirPth1.ReverseFind('//'); int indx= strSrcDirPth1.GetLength() - index; CString strSrcDirPth2 = strSrcDirPth1.Right(indx); CString RemoteDir=strSrcDirPth; CString dirpath=strTrgfDirPath + strSrcDirPth2; CreateDirectory(dirpath,NULL); CString LocalDir = dirpath; CFTPUpDwnldManager *pCFTPUpDMngr = (CFTPUpDwnldManager *)lParam; if(NULL == pCFTPUpDMngr) { return bRetVal; } CFTPManager *pFTPManager = (CFTPManager *)lParam; if(NULL == pFTPManager) { return bRetVal; } CNSInternetSession* pInternetSession = pFTPManager->GetInternetSessionPtr(); if(NULL == pInternetSession) { return bRetVal; } pCFTPUpDMngr->CloseFTPConnection(); if(-1 == pCFTPUpDMngr->GetFTPConnection()) { return bRetVal; } CFtpFileFind fileFind(pFtpConnection,0); CString strFindFilePath = RemoteDir + "/*.*"; BOOL bContinue = fileFind.FindFile(strFindFilePath) ; DWORD dw = GetLastError(); if (!bContinue) { // the directory is empty; just close up and return. fileFind.Close(); return bRetVal; } while (bContinue) { bContinue = fileFind.FindNextFile(); DWORD dw = GetLastError(); CString tempDirName = fileFind.GetFileName(); CString tempDirPath = fileFind.GetFilePath(); CString tempFileUrl= fileFind.GetFileURL(); if(fileFind.IsDots()) { continue; } if (fileFind.IsDirectory()) { CString NewSrcDir = RemoteDir + "/" + tempDirName; //CString NewTrgDIr = LocalDir + "/" + tempDirName; CString NewTrgDir