ToDieFor
2006-01-26 15:49:04 UTC
I finally got the InternetGetLastResponeInfo to work, it gives back what
looks like garbage. I am enclosing the code that I am using along with the
output that I'm getting back.
TIA for help
Code Block Begins:
=================
int main()
{
CInternetSession * inetSession = NULL;
CFtpConnection * midasConnect = NULL;
CFtpFileFind * curFile = NULL;
DWORD dwServiceType = AFX_INET_SERVICE_FTP;
unsigned short ftpPort = 21;
bool bWorking = false;
CString ftpSiteName = <ftp server address>,
ftpSiteUID = <username>,
ftpSitePWD = <password>,
ftpSubDir = "ft/",
localDir = "",
fileName = "",
newFileName = "",
errDesc = "";
unsigned int byteCt = 0,
fileSize = 0;
CTime start = NULL,
end = NULL;
CTimeSpan diff = NULL;
DWORD errNo = 0,
errSize = 0;
// LPTSTR errDesc = "";
//#if _DEBUG
printf("Getting Session\n");
//#endif
inetSession = new CInternetSession("MIDAS Updater 2 - Alpha",
1, PRE_CONFIG_INTERNET_ACCESS);
//#if _DEBUG
printf("Attempting to find the ftp site\n");
//#endif
if (!AfxParseURL(ftpSiteName, dwServiceType, ftpSiteName, ftpSubDir,
ftpPort))
{
ftpSiteName = "mercnet.mercurymarine.com";
ftpSubDir = GetSubDir();
//#if _DEBUG
printf("Sub directory that was found is %s\n", ftpSubDir);
printf("Getting Connection\n");
//#endif
try
{
midasConnect = inetSession->GetFtpConnection(ftpSiteName,
ftpSiteUID, ftpSitePWD,
INTERNET_DEFAULT_FTP_PORT);
//#if _DEBUG
printf("Setting the directory\n");
//#endif
midasConnect->SetCurrentDirectory(ftpSubDir);
//#if _DEBUG
printf("Finding Files\n");
//#endif
start = CTime::GetCurrentTime();
curFile = new CFtpFileFind(midasConnect);
bWorking = (curFile->FindFile("*.zip", INTERNET_FLAG_RAW_DATA) != 0);
if (bWorking)
printf("Files were found\n\n");
else
{
printf("No files were found\n\n");
errNo = GetLastError();
switch(errNo)
{
case 0:
printf("No error found");
break;
case 12003:
{
InternetGetLastResponseInfo(&errNo, (LPTSTR) &errDesc, &errSize);
printf("Error 12003\nExtended information:\n%s", (LPTSTR)
&errDesc);
break;
}
case 12031:
printf("Server was busy, please try again later");
break;
case 12007:
printf("Firewall blocking connection to ftp server, please
unblock and try again");
break;
default:
break;
}
}
localDir = GetLocalFileDir() + "Update\\";
while (bWorking)
{
//#if _DEBUG
printf("Retrieving File Information\n");
//#endif
bWorking = (curFile->FindNextFile() != 0);
// printf("File Information Retrieved, writing information\n");
// printf("File: %s\tSize: %d\n", curFile->GetFileName(),
curFile->GetLength());
fileSize = curFile->GetLength();
byteCt += fileSize;
printf ("File Name: %s\tFile Size: %d\n", curFile->GetFileName(),
fileSize);
// newFileName = curFile->GetFileName().Right(12);
// if (newFileName[0] == '.')
// newFileName = newFileName.Right(11);
// TCHAR tmpData[1000000];
// CInternetFile * inetFile =
midasConnect->OpenFile(curFile->GetFileName());
//#if _DEBUG
printf("Reading File Now \n");
//#endif
// inetFile->ReadString(tmpData, byteCt);
// CFile * tmpFile = new CFile();
//#if _DEBUG
// printf("Writing to local dir \n");
//#endif
// tmpFile->Open(localDir + newFileName, CFile::OpenFlags::modeWrite);
// tmpFile->SetFilePath(GetLocalFileDir() + "Update\\");
// tmpFile->Write(tmpData, byteCt);
}
}
catch(CInternetException* pEx)
{
TCHAR sz[1024];
pEx->GetErrorMessage(sz, 1024);
printf("Internet Error! %s\n", sz);
pEx->Delete();
}
catch(CException * pEx)
{
TCHAR sz[1024];
pEx->GetErrorMessage(sz, 1024);
printf("Error! %s\n", sz);
pEx->Delete();
}
}
else
printf("SiteName: %s\tService Type: %d\nPort #: %d\tSubDir: %s\n",
ftpSiteName, dwServiceType, ftpPort, ftpSubDir);
end = CTime::GetCurrentTime();
diff = end - start;
//#if _DEBUG
printf("Default Path for Files is : %s\n", localDir);
printf("Total bytes found on the server %d\n", byteCt);
printf("Total time taken was %d second(s)\n", diff.GetSeconds());
//#endif
printf("Done!");
midasConnect->Close();
delete midasConnect;
inetSession->Close();
delete inetSession;
Sleep(15000);
return 0;
}
===============
Output
===============
Getting Session
Attempting to find the ftp site
Sub directory that was found it ft/dom/dlr
Getting Connection
Setting the directory
Finding Files
No files were found
Error 12003
Extended Information:
(garbage data - ASCII Characters)Path for Files is : <path>
Total bytes found on the server 0
Total time taken was 46 seconds
Done!
==========
End output
==========
looks like garbage. I am enclosing the code that I am using along with the
output that I'm getting back.
TIA for help
Code Block Begins:
=================
int main()
{
CInternetSession * inetSession = NULL;
CFtpConnection * midasConnect = NULL;
CFtpFileFind * curFile = NULL;
DWORD dwServiceType = AFX_INET_SERVICE_FTP;
unsigned short ftpPort = 21;
bool bWorking = false;
CString ftpSiteName = <ftp server address>,
ftpSiteUID = <username>,
ftpSitePWD = <password>,
ftpSubDir = "ft/",
localDir = "",
fileName = "",
newFileName = "",
errDesc = "";
unsigned int byteCt = 0,
fileSize = 0;
CTime start = NULL,
end = NULL;
CTimeSpan diff = NULL;
DWORD errNo = 0,
errSize = 0;
// LPTSTR errDesc = "";
//#if _DEBUG
printf("Getting Session\n");
//#endif
inetSession = new CInternetSession("MIDAS Updater 2 - Alpha",
1, PRE_CONFIG_INTERNET_ACCESS);
//#if _DEBUG
printf("Attempting to find the ftp site\n");
//#endif
if (!AfxParseURL(ftpSiteName, dwServiceType, ftpSiteName, ftpSubDir,
ftpPort))
{
ftpSiteName = "mercnet.mercurymarine.com";
ftpSubDir = GetSubDir();
//#if _DEBUG
printf("Sub directory that was found is %s\n", ftpSubDir);
printf("Getting Connection\n");
//#endif
try
{
midasConnect = inetSession->GetFtpConnection(ftpSiteName,
ftpSiteUID, ftpSitePWD,
INTERNET_DEFAULT_FTP_PORT);
//#if _DEBUG
printf("Setting the directory\n");
//#endif
midasConnect->SetCurrentDirectory(ftpSubDir);
//#if _DEBUG
printf("Finding Files\n");
//#endif
start = CTime::GetCurrentTime();
curFile = new CFtpFileFind(midasConnect);
bWorking = (curFile->FindFile("*.zip", INTERNET_FLAG_RAW_DATA) != 0);
if (bWorking)
printf("Files were found\n\n");
else
{
printf("No files were found\n\n");
errNo = GetLastError();
switch(errNo)
{
case 0:
printf("No error found");
break;
case 12003:
{
InternetGetLastResponseInfo(&errNo, (LPTSTR) &errDesc, &errSize);
printf("Error 12003\nExtended information:\n%s", (LPTSTR)
&errDesc);
break;
}
case 12031:
printf("Server was busy, please try again later");
break;
case 12007:
printf("Firewall blocking connection to ftp server, please
unblock and try again");
break;
default:
break;
}
}
localDir = GetLocalFileDir() + "Update\\";
while (bWorking)
{
//#if _DEBUG
printf("Retrieving File Information\n");
//#endif
bWorking = (curFile->FindNextFile() != 0);
// printf("File Information Retrieved, writing information\n");
// printf("File: %s\tSize: %d\n", curFile->GetFileName(),
curFile->GetLength());
fileSize = curFile->GetLength();
byteCt += fileSize;
printf ("File Name: %s\tFile Size: %d\n", curFile->GetFileName(),
fileSize);
// newFileName = curFile->GetFileName().Right(12);
// if (newFileName[0] == '.')
// newFileName = newFileName.Right(11);
// TCHAR tmpData[1000000];
// CInternetFile * inetFile =
midasConnect->OpenFile(curFile->GetFileName());
//#if _DEBUG
printf("Reading File Now \n");
//#endif
// inetFile->ReadString(tmpData, byteCt);
// CFile * tmpFile = new CFile();
//#if _DEBUG
// printf("Writing to local dir \n");
//#endif
// tmpFile->Open(localDir + newFileName, CFile::OpenFlags::modeWrite);
// tmpFile->SetFilePath(GetLocalFileDir() + "Update\\");
// tmpFile->Write(tmpData, byteCt);
}
}
catch(CInternetException* pEx)
{
TCHAR sz[1024];
pEx->GetErrorMessage(sz, 1024);
printf("Internet Error! %s\n", sz);
pEx->Delete();
}
catch(CException * pEx)
{
TCHAR sz[1024];
pEx->GetErrorMessage(sz, 1024);
printf("Error! %s\n", sz);
pEx->Delete();
}
}
else
printf("SiteName: %s\tService Type: %d\nPort #: %d\tSubDir: %s\n",
ftpSiteName, dwServiceType, ftpPort, ftpSubDir);
end = CTime::GetCurrentTime();
diff = end - start;
//#if _DEBUG
printf("Default Path for Files is : %s\n", localDir);
printf("Total bytes found on the server %d\n", byteCt);
printf("Total time taken was %d second(s)\n", diff.GetSeconds());
//#endif
printf("Done!");
midasConnect->Close();
delete midasConnect;
inetSession->Close();
delete inetSession;
Sleep(15000);
return 0;
}
===============
Output
===============
Getting Session
Attempting to find the ftp site
Sub directory that was found it ft/dom/dlr
Getting Connection
Setting the directory
Finding Files
No files were found
Error 12003
Extended Information:
(garbage data - ASCII Characters)Path for Files is : <path>
Total bytes found on the server 0
Total time taken was 46 seconds
Done!
==========
End output
==========