D
David Jacques
I have to write a console application which will fetch a zip on a daily
basis.
This zip file is hotlinked in a web page. The name of this .zip file will
change every day. I've been able to start the session, open the URL,
read each line, and get the line with the .zip file URL in it no problem.
Where I am running intro trouble is writing the zip file to disk as binary.
I'm following the example from the VC++ Online Help reference to
CFile::Open(). Can anyone see what I am doing wrong ?
thanks in advance.
#include <afx.h>
#include <afxwin.h>
#include <afxinet.h>
#include <iostream>
#include <stdlib.h>
int main(int argc, _TCHAR* argv[])
{
CStdioFile* pRemoteURLFile;
CStdioFile* pRemoteZipFile;
CFile* pLocalZipFile;
CInternetSession pSessionURL("URLSession");
CInternetSession pSessionZip("ZipSession");
char* ziptag = "shapefile";
CString sURL;
CString sZipURL;
CString sReadLine;
char* pFileName = "test.dat";
int iFound;
int iNumLines;
UINT nBytesRead;
char pbuf[100];
CFileException cFileErr;
pRemoteURLFile = NULL;
pRemoteZipFile = NULL;
pLocalZipFile = NULL;
iNumLines = nBytesRead = 0;
sURL = "http://activefiremaps.fs.fed.us/fireptdata/modisfire_2004.htm";
pRemoteURLFile =
pSessionURL.OpenURL(sURL,1,INTERNET_FLAG_TRANSFER_BINARY,NULL,NULL);
while (pRemoteURLFile->ReadString(sReadLine))
{
iNumLines ++;
iFound = sReadLine.Find("shapefile");
if (iFound > 0)
{
sZipURL = getZIPURL(sReadLine,ziptag,sURL);
}
}
delete pRemoteURLFile;
pSessionURL.Close;
pSessionZip.OpenURL(sZipURL,1,INTERNET_FLAG_TRANSFER_BINARY,NULL,NULL);
pRemoteZipFile =
pSessionZip.OpenURL(sZipURL,1,INTERNET_FLAG_TRANSFER_BINARY,NULL,NULL);
//** The below line fails **
if( pLocalZipFile->Open(pFileName, CFile::modeCreate | CFile::modeWrite |
CFile::typeBinary, &cFileErr ) )
{
while (pRemoteZipFile->Read(pbuf,100))
{
//count bytes read to see if size of file is correct
nBytesRead = nBytesRead + sizeof(pbuf);
//** write binary date to pLocalZipFile here **
}
printf("%d bytes read from remote file %s\n",nBytesRead,sZipURL);
delete pRemoteZipFile;
pSessionZip.Close;
return 0;
}
}
basis.
This zip file is hotlinked in a web page. The name of this .zip file will
change every day. I've been able to start the session, open the URL,
read each line, and get the line with the .zip file URL in it no problem.
Where I am running intro trouble is writing the zip file to disk as binary.
I'm following the example from the VC++ Online Help reference to
CFile::Open(). Can anyone see what I am doing wrong ?
thanks in advance.
#include <afx.h>
#include <afxwin.h>
#include <afxinet.h>
#include <iostream>
#include <stdlib.h>
int main(int argc, _TCHAR* argv[])
{
CStdioFile* pRemoteURLFile;
CStdioFile* pRemoteZipFile;
CFile* pLocalZipFile;
CInternetSession pSessionURL("URLSession");
CInternetSession pSessionZip("ZipSession");
char* ziptag = "shapefile";
CString sURL;
CString sZipURL;
CString sReadLine;
char* pFileName = "test.dat";
int iFound;
int iNumLines;
UINT nBytesRead;
char pbuf[100];
CFileException cFileErr;
pRemoteURLFile = NULL;
pRemoteZipFile = NULL;
pLocalZipFile = NULL;
iNumLines = nBytesRead = 0;
sURL = "http://activefiremaps.fs.fed.us/fireptdata/modisfire_2004.htm";
pRemoteURLFile =
pSessionURL.OpenURL(sURL,1,INTERNET_FLAG_TRANSFER_BINARY,NULL,NULL);
while (pRemoteURLFile->ReadString(sReadLine))
{
iNumLines ++;
iFound = sReadLine.Find("shapefile");
if (iFound > 0)
{
sZipURL = getZIPURL(sReadLine,ziptag,sURL);
}
}
delete pRemoteURLFile;
pSessionURL.Close;
pSessionZip.OpenURL(sZipURL,1,INTERNET_FLAG_TRANSFER_BINARY,NULL,NULL);
pRemoteZipFile =
pSessionZip.OpenURL(sZipURL,1,INTERNET_FLAG_TRANSFER_BINARY,NULL,NULL);
//** The below line fails **
if( pLocalZipFile->Open(pFileName, CFile::modeCreate | CFile::modeWrite |
CFile::typeBinary, &cFileErr ) )
{
while (pRemoteZipFile->Read(pbuf,100))
{
//count bytes read to see if size of file is correct
nBytesRead = nBytesRead + sizeof(pbuf);
//** write binary date to pLocalZipFile here **
}
printf("%d bytes read from remote file %s\n",nBytesRead,sZipURL);
delete pRemoteZipFile;
pSessionZip.Close;
return 0;
}
}