Discussion:
Am I reading the information correctly?
(too old to reply)
ToDieFor
2006-01-26 15:49:04 UTC
Permalink
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
==========
Scherbina Vladimir
2006-01-26 16:35:11 UTC
Permalink
Your code is not compiling, where is GetLocalFileDir function ?

Don't post code as a text in message, it's hard to compile it then, simply
make attachment with compilable code.

--
Vladimir
Post by ToDieFor
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
=================
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)
{
printf("No error found");
break;
{
InternetGetLastResponseInfo(&errNo, (LPTSTR) &errDesc, &errSize);
printf("Error 12003\nExtended information:\n%s", (LPTSTR)
&errDesc);
break;
}
printf("Server was busy, please try again later");
break;
printf("Firewall blocking connection to ftp server, please
unblock and try again");
break;
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
(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
==========
ToDieFor
2006-01-26 17:32:03 UTC
Permalink
I am using the online newsgroup browser, how do I attach the files?
Post by Scherbina Vladimir
Your code is not compiling, where is GetLocalFileDir function ?
Don't post code as a text in message, it's hard to compile it then, simply
make attachment with compilable code.
--
Vladimir
Post by ToDieFor
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
=================
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)
{
printf("No error found");
break;
{
InternetGetLastResponseInfo(&errNo, (LPTSTR) &errDesc, &errSize);
printf("Error 12003\nExtended information:\n%s", (LPTSTR)
&errDesc);
break;
}
printf("Server was busy, please try again later");
break;
printf("Firewall blocking connection to ftp server, please
unblock and try again");
break;
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
(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
==========
Scherbina Vladimir
2006-01-26 17:34:28 UTC
Permalink
I use O.E., so there is no problem to attach something.

--
Vladimir
Post by ToDieFor
I am using the online newsgroup browser, how do I attach the files?
Post by Scherbina Vladimir
Your code is not compiling, where is GetLocalFileDir function ?
Don't post code as a text in message, it's hard to compile it then, simply
make attachment with compilable code.
--
Vladimir
Post by ToDieFor
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
=================
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)
{
printf("No error found");
break;
{
InternetGetLastResponseInfo(&errNo, (LPTSTR) &errDesc, &errSize);
printf("Error 12003\nExtended information:\n%s", (LPTSTR)
&errDesc);
break;
}
printf("Server was busy, please try again later");
break;
printf("Firewall blocking connection to ftp server, please
unblock and try again");
break;
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
(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
==========
ToDieFor
2006-01-26 18:10:04 UTC
Permalink
Ok, I'm reposting the code then so that it will compile and run.

-------start of code block ----
#include "afxinet.h"
#include <time.h>
#pragma comment(lib, "wininet.lib")

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 = "mercnet.mercurymarine.com",
ftpSiteUID = "midasft",
ftpSitePWD = "mercmarine",
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 = "ft/dom/dlr";
//#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\n", 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 = "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;
}
----end of code block----

Just past the code between the blocks into a blank .cpp file and it will
compile now. It's expected to give a list of files on the server and then
disconnect. This will happen most of the time, sometimes I get an error
12003, which then gives the garbage data from the error 12003 case execution.
What I want to know is if the garbage data is what's actually on the server,
or if I'm retrieving the data correctly from the server using the function.
Post by Scherbina Vladimir
I use O.E., so there is no problem to attach something.
--
Vladimir
Post by ToDieFor
I am using the online newsgroup browser, how do I attach the files?
Post by Scherbina Vladimir
Your code is not compiling, where is GetLocalFileDir function ?
Don't post code as a text in message, it's hard to compile it then, simply
make attachment with compilable code.
--
Vladimir
Post by ToDieFor
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
=================
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)
{
printf("No error found");
break;
{
InternetGetLastResponseInfo(&errNo, (LPTSTR) &errDesc, &errSize);
printf("Error 12003\nExtended information:\n%s", (LPTSTR)
&errDesc);
break;
}
printf("Server was busy, please try again later");
break;
printf("Firewall blocking connection to ftp server, please
unblock and try again");
break;
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
(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
==========
Scherbina Vladimir
2006-02-01 11:16:29 UTC
Permalink
For the future - don't post passwords and logins for valid ftp servers. I
traced your code, there is not garbage in response from ftp server. Can you
describe more precise testcase ?

--
Vladimir
Post by ToDieFor
Ok, I'm reposting the code then so that it will compile and run.
-------start of code block ----
#include "afxinet.h"
#include <time.h>
#pragma comment(lib, "wininet.lib")
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 = "mercnet.mercurymarine.com",
ftpSiteUID = "midasft",
ftpSitePWD = "mercmarine",
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 = "ft/dom/dlr";
//#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)
{
printf("No error found");
break;
{
InternetGetLastResponseInfo(&errNo, (LPTSTR) &errDesc, &errSize);
printf("Error 12003\nExtended information:\n%s\n", errDesc);
break;
}
printf("Server was busy, please try again later");
break;
printf("Firewall blocking connection to ftp server, please
unblock and try again");
break;
break;
}
}
localDir = "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;
}
----end of code block----
Just past the code between the blocks into a blank .cpp file and it will
compile now. It's expected to give a list of files on the server and then
disconnect. This will happen most of the time, sometimes I get an error
12003, which then gives the garbage data from the error 12003 case execution.
What I want to know is if the garbage data is what's actually on the server,
or if I'm retrieving the data correctly from the server using the function.
Post by Scherbina Vladimir
I use O.E., so there is no problem to attach something.
--
Vladimir
Post by ToDieFor
I am using the online newsgroup browser, how do I attach the files?
Post by Scherbina Vladimir
Your code is not compiling, where is GetLocalFileDir function ?
Don't post code as a text in message, it's hard to compile it then, simply
make attachment with compilable code.
--
Vladimir
Post by ToDieFor
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
=================
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)
{
printf("No error found");
break;
{
InternetGetLastResponseInfo(&errNo, (LPTSTR) &errDesc, &errSize);
printf("Error 12003\nExtended information:\n%s", (LPTSTR)
&errDesc);
break;
}
printf("Server was busy, please try again later");
break;
printf("Firewall blocking connection to ftp server, please
unblock and try again");
break;
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
(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
==========
ToDieFor
2006-02-01 17:00:49 UTC
Permalink
That's why previously I didn't post the entire code, and commented out the
information. When I was asked for the code that would compile I had to
supply that information to get it to run.
The garbage information was being returned because of the type of string
that I was using. InternetGetLastResponseInfo requires the string to be of
type TCHAR array, which I was not using. I am trying it now using a TCHAR
array of 512 bytes to see if it will return the actual error / extended data.
Post by Scherbina Vladimir
For the future - don't post passwords and logins for valid ftp servers. I
traced your code, there is not garbage in response from ftp server. Can you
describe more precise testcase ?
--
Vladimir
Post by ToDieFor
Ok, I'm reposting the code then so that it will compile and run.
-------start of code block ----
#include "afxinet.h"
#include <time.h>
#pragma comment(lib, "wininet.lib")
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 = "mercnet.mercurymarine.com",
ftpSiteUID = "midasft",
ftpSitePWD = "mercmarine",
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 = "ft/dom/dlr";
//#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)
{
printf("No error found");
break;
{
InternetGetLastResponseInfo(&errNo, (LPTSTR) &errDesc, &errSize);
printf("Error 12003\nExtended information:\n%s\n", errDesc);
break;
}
printf("Server was busy, please try again later");
break;
printf("Firewall blocking connection to ftp server, please
unblock and try again");
break;
break;
}
}
localDir = "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;
}
----end of code block----
Just past the code between the blocks into a blank .cpp file and it will
compile now. It's expected to give a list of files on the server and then
disconnect. This will happen most of the time, sometimes I get an error
12003, which then gives the garbage data from the error 12003 case execution.
What I want to know is if the garbage data is what's actually on the server,
or if I'm retrieving the data correctly from the server using the function.
Post by Scherbina Vladimir
I use O.E., so there is no problem to attach something.
--
Vladimir
Post by ToDieFor
I am using the online newsgroup browser, how do I attach the files?
Post by Scherbina Vladimir
Your code is not compiling, where is GetLocalFileDir function ?
Don't post code as a text in message, it's hard to compile it then, simply
make attachment with compilable code.
--
Vladimir
Post by ToDieFor
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
=================
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)
{
printf("No error found");
break;
{
InternetGetLastResponseInfo(&errNo, (LPTSTR) &errDesc, &errSize);
printf("Error 12003\nExtended information:\n%s", (LPTSTR)
&errDesc);
break;
}
printf("Server was busy, please try again later");
break;
printf("Firewall blocking connection to ftp server, please
unblock and try again");
break;
break;
}
}
Scherbina Vladimir
2006-02-01 21:18:13 UTC
Permalink
Post by ToDieFor
That's why previously I didn't post the entire code, and commented out the
information. When I was asked for the code that would compile I had to
supply that information to get it to run.
You could change password and real name to "blablabla". That would not
influence on compilation.
Post by ToDieFor
The garbage information was being returned because of the type of string
that I was using. InternetGetLastResponseInfo requires the string to be of
type TCHAR array, which I was not using. I am trying it now using a TCHAR
array of 512 bytes to see if it will return the actual error / extended data.
--
Vladimir
Loading...