Newsgroups : Microsoft : microsoft.public.inetsdk.programming.wininet : 2006 Jan : Am I reading the information correctly?

www.cryer.info
Managed Newsgroup Archive

Am I reading the information correctly?

Subject:Am I reading the information correctly?
Posted by:"ToDieFor" (todief..@discussions.microsoft.com)
Date:Thu, 26 Jan 2006 07:49:04

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
");
//#endif
        inetSession = new CInternetSession("MIDAS Updater 2 - Alpha",
                1, PRE_CONFIG_INTERNET_ACCESS);
//#if _DEBUG
        printf("Attempting to find the ftp site
");
//#endif
        if (!AfxParseURL(ftpSiteName, dwServiceType, ftpSiteName, ftpSubDir,
ftpPort))
        {
                ftpSiteName = "mercnet.mercurymarine.com";
                ftpSubDir = GetSubDir();
//#if _DEBUG
                printf("Sub directory that was found is %s
", ftpSubDir);
                printf("Getting Connection
");
//#endif
                try
                {
                        midasConnect = inetSession->GetFtpConnection(ftpSiteName,
                                ftpSiteUID, ftpSitePWD,
                                INTERNET_DEFAULT_FTP_PORT);
//#if _DEBUG
                        printf("Setting the directory
");
//#endif
                        midasConnect->SetCurrentDirectory(ftpSubDir);
//#if _DEBUG
                        printf("Finding Files
");
//#endif
                        start = CTime::GetCurrentTime();
                        curFile = new CFtpFileFind(midasConnect);
                        bWorking = (curFile->FindFile("*.zip", INTERNET_FLAG_RAW_DATA) != 0);
                        if (bWorking)
                                printf("Files were found

");
                        else
                        {
                                printf("No files were found

");
                                errNo = GetLastError();
                                switch(errNo)
                                {
                                        case 0:
                                                printf("No error found");
                                                break;
                                        case 12003:
                                        {
                                                InternetGetLastResponseInfo(&errNo, (LPTSTR) &errDesc, &errSize);
                                                printf("Error 12003
Extended information:
%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
");
//#endif
                                bWorking = (curFile->FindNextFile() != 0);
//                                printf("File Information Retrieved, writing information
");
//                                printf("File: %s\tSize: %d
", curFile->GetFileName(),
curFile->GetLength());
                                fileSize = curFile->GetLength();
                                byteCt += fileSize;
                                printf ("File Name: %s\tFile Size: %d
", 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
");
//#endif
//                                inetFile->ReadString(tmpData, byteCt);
//                                CFile * tmpFile = new CFile();
//#if _DEBUG
//                                printf("Writing to local dir
");
//#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
", sz);
                        pEx->Delete();
                }
                catch(CException * pEx)
                {
                        TCHAR sz[1024];
                        pEx->GetErrorMessage(sz, 1024);
                        printf("Error! %s
", sz);
                        pEx->Delete();
                }
        }
        else
                printf("SiteName: %s\tService Type: %d
Port #: %d\tSubDir: %s
",
                        ftpSiteName, dwServiceType, ftpPort, ftpSubDir);
        end = CTime::GetCurrentTime();
        diff = end - start;
//#if _DEBUG
        printf("Default Path for Files is : %s
", localDir);
        printf("Total bytes found on the server %d
", byteCt);
        printf("Total time taken was %d second(s)
", 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
==========

Replies:

www.cryer.info
Managed Newsgroup Archive