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. InternetFindNextFile function falis

InternetFindNextFile function falis

Scheduled Pinned Locked Moved C / C++ / MFC
comsysadminhelp
5 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.
  • O Offline
    O Offline
    onlyjaypatel
    wrote on last edited by
    #1

    I want all the filenames in perticular folder of web server with http call. InternetFindNextFile function falis some sample of code. . . CString sUserAgentName = "Microsoft Internet Explorer"; DWORD dwAccessType = INTERNET_OPEN_TYPE_PRECONFIG ; DWORD dwFlags =INTERNET_FLAG_DONT_CACHE|INTERNET_FLAG_RELOAD ; //pInternetSession = new CInternetSession(sUserAgentName,dwContext,dwAccessType,NULL,NULL,dwFlags); CString sUrl="http://www.test.com/1"; WIN32_FIND_DATA wfd; HINTERNET hInternetFind,hInternetOpen = InternetOpen(sUserAgentName,dwAccessType,NULL,NULL,0); CStringArray saFileName, saDirectoryName; CString sName; CString sServerName , sServerObjectName ; DWORD dwServiceType = 0 ; INTERNET_PORT nServerPort = 0; CString strHeaders ; CString sUserName = ""; CString sPassword ; DWORD dwContext = 0; if(AfxParseURL(sUrl,dwServiceType,sServerName,sServerObjectName,nServerPort)==FALSE) { AfxMessageBox("AfxParseURL() Fails"); return false; } int err; //pConnection = pInternetSession->GetHttpConnection(sServerName,nServerPort,sUserName,sPassword); //HINTERNET hInternetConnect = ::InternetConnect(hInternetOpen,sServerName,nServerPort,sUserName,sPassword,INTERNET_SERVICE_HTTP,dwFlags,dwContext); //err = GetLastError(); //hInternetFind = FtpFindFirstFile(hInternetConnect,"*.*",&wfd,0,0); /*if i try function FtpFindFirstFile than it returns null and errorcode is ERROR_INTERNET_INCORRECT_HANDLE_TYPE(12018) */ //err = GetLastError(); hInternetFind = InternetOpenUrl(hInternetOpen,sUrl,NULL,0,INTERNET_FLAG_RAW_DATA| INTERNET_FLAG_RELOAD| INTERNET_FLAG_DONT_CACHE,0); /* if i try InternetOpenUrl than it retrn not null but when InternetFindNextFile is called than it returns FALSE ERROR_INTERNET_INVALID_OPERATION(12016)*/ err = GetLastError(); if (hInternetFind ==NULL) { AfxMessageBox("(hInternetFind == NULL)"); } if (InternetFindNextFile(hInternetFind, &wfd) == FALSE) { err = GetLastError(); AfxMessageBox("(InternetFindNextFile = fails)"); } do { if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { sName = (const char*) &wfd.cFileName; if(!sName.IsEmpty()) { if (sName.GetAt(0) == '.') continue; saDirectoryName.Add(sName); } } else saFileName.Add(sName); } while (InternetFindNextFile (hInternetFind, &wfd)); InternetCloseHandle(hInternetFind); . . . :rose: thanx

    D 1 Reply Last reply
    0
    • O onlyjaypatel

      I want all the filenames in perticular folder of web server with http call. InternetFindNextFile function falis some sample of code. . . CString sUserAgentName = "Microsoft Internet Explorer"; DWORD dwAccessType = INTERNET_OPEN_TYPE_PRECONFIG ; DWORD dwFlags =INTERNET_FLAG_DONT_CACHE|INTERNET_FLAG_RELOAD ; //pInternetSession = new CInternetSession(sUserAgentName,dwContext,dwAccessType,NULL,NULL,dwFlags); CString sUrl="http://www.test.com/1"; WIN32_FIND_DATA wfd; HINTERNET hInternetFind,hInternetOpen = InternetOpen(sUserAgentName,dwAccessType,NULL,NULL,0); CStringArray saFileName, saDirectoryName; CString sName; CString sServerName , sServerObjectName ; DWORD dwServiceType = 0 ; INTERNET_PORT nServerPort = 0; CString strHeaders ; CString sUserName = ""; CString sPassword ; DWORD dwContext = 0; if(AfxParseURL(sUrl,dwServiceType,sServerName,sServerObjectName,nServerPort)==FALSE) { AfxMessageBox("AfxParseURL() Fails"); return false; } int err; //pConnection = pInternetSession->GetHttpConnection(sServerName,nServerPort,sUserName,sPassword); //HINTERNET hInternetConnect = ::InternetConnect(hInternetOpen,sServerName,nServerPort,sUserName,sPassword,INTERNET_SERVICE_HTTP,dwFlags,dwContext); //err = GetLastError(); //hInternetFind = FtpFindFirstFile(hInternetConnect,"*.*",&wfd,0,0); /*if i try function FtpFindFirstFile than it returns null and errorcode is ERROR_INTERNET_INCORRECT_HANDLE_TYPE(12018) */ //err = GetLastError(); hInternetFind = InternetOpenUrl(hInternetOpen,sUrl,NULL,0,INTERNET_FLAG_RAW_DATA| INTERNET_FLAG_RELOAD| INTERNET_FLAG_DONT_CACHE,0); /* if i try InternetOpenUrl than it retrn not null but when InternetFindNextFile is called than it returns FALSE ERROR_INTERNET_INVALID_OPERATION(12016)*/ err = GetLastError(); if (hInternetFind ==NULL) { AfxMessageBox("(hInternetFind == NULL)"); } if (InternetFindNextFile(hInternetFind, &wfd) == FALSE) { err = GetLastError(); AfxMessageBox("(InternetFindNextFile = fails)"); } do { if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { sName = (const char*) &wfd.cFileName; if(!sName.IsEmpty()) { if (sName.GetAt(0) == '.') continue; saDirectoryName.Add(sName); } } else saFileName.Add(sName); } while (InternetFindNextFile (hInternetFind, &wfd)); InternetCloseHandle(hInternetFind); . . . :rose: thanx

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      jay_p_patel wrote:

      InternetFindNextFile function falis

      So what does GetLastError() return?


      "A good athlete is the result of a good and worthy opponent." - David Crow

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      O 1 Reply Last reply
      0
      • D David Crow

        jay_p_patel wrote:

        InternetFindNextFile function falis

        So what does GetLastError() return?


        "A good athlete is the result of a good and worthy opponent." - David Crow

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        O Offline
        O Offline
        onlyjaypatel
        wrote on last edited by
        #3

        i wrote in that code ERROR_INTERNET_INVALID_OPERATION(12016)

        D 1 Reply Last reply
        0
        • O onlyjaypatel

          i wrote in that code ERROR_INTERNET_INVALID_OPERATION(12016)

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Your code snippet is next to impossible to read. I can't tell what you've got commented out and what's actual code. Please reformat it AND make use of the <pre> tags. You need something similar to:

          HINTERNET hOpen = InternetOpen(...);
          if (hOpen != NULL)
          {
          HINTERNET hConnect = InternetConnect(hOpen, ...);
          if (hConnect != NULL)
          {
          WIN32_FIND_DATA findData;

              HINTERNET hFind = FtpFindFirstFile(hConnect, NULL, &findData, ...);
              if (hFind != NULL)
              {
                  do
                  {
                      ...
                  } while (InternetFindNextFile(hFind, &findData))
              }
          }
          

          }


          "A good athlete is the result of a good and worthy opponent." - David Crow

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          O 1 Reply Last reply
          0
          • D David Crow

            Your code snippet is next to impossible to read. I can't tell what you've got commented out and what's actual code. Please reformat it AND make use of the <pre> tags. You need something similar to:

            HINTERNET hOpen = InternetOpen(...);
            if (hOpen != NULL)
            {
            HINTERNET hConnect = InternetConnect(hOpen, ...);
            if (hConnect != NULL)
            {
            WIN32_FIND_DATA findData;

                HINTERNET hFind = FtpFindFirstFile(hConnect, NULL, &findData, ...);
                if (hFind != NULL)
                {
                    do
                    {
                        ...
                    } while (InternetFindNextFile(hFind, &findData))
                }
            }
            

            }


            "A good athlete is the result of a good and worthy opponent." - David Crow

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            O Offline
            O Offline
            onlyjaypatel
            wrote on last edited by
            #5

            Hello Sir, The code you send me that i already tried. when i use HINTERNET hFind = FtpFindFirstFile(hConnect, NULL, &findData, ...); it returns hFind = NULL and in GetLastError it returns Error No.12018 ERROR_INTERNET_INCORRECT_HANDLE_TYPE i read in msdn that we can use InternetOpenUrl in place of FtpFindFirstFile HINTERNET hFind = InternetOpenUrlhInternetOpen,sUrl,NULL,0,INTERNET_FLAG_RAW_DATA| INTERNET_FLAG_RELOAD| INTERNET_FLAG_DONT_CACHE,0); now hFind is not Null but when i use this hFind in InternetFindNextFile API than it return false. So this is the problem. Anyway thanx for helping me. sorry for ur inconvinience. :):rose:

            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