InternetFindNextFile function falis
-
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
-
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
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
-
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
i wrote in that code ERROR_INTERNET_INVALID_OPERATION(12016)
-
i wrote in that code ERROR_INTERNET_INVALID_OPERATION(12016)
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
-
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
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: