Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem for Download directory FTP VC++ code

Problem for Download directory FTP VC++ code

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++database
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chetanjoshi9
    wrote on last edited by
    #1

    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

    P 1 Reply Last reply
    0
    • C chetanjoshi9

      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

      P Offline
      P Offline
      ptr_Electron
      wrote on last edited by
      #2

      http://www.codeproject.com/KB/IP/mdftpclient1.aspx[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups