Sample code (bit long) CInternetFile::ReadString and CInternetFile 
Author Message
 Sample code (bit long) CInternetFile::ReadString and CInternetFile

Hi !!!!!!!!!!!!!!!!!!

I used the following code to read and write data to my TRIPOD server: What
is wrong here? This is being used for storing a user's name and his/her IP
address.
Thanks a zzzzzzziiiillllion ...

void CMyDlg::OnRead ()
{
////////////////////////////////////////////////////////////////////////////
///
/* MY CODE FOR READING STARTS HERE */
////////////////////////////////////////////////////////////////////////////
///
char szUser[100];
char szIP[100];

 CInternetSession session("My Session");
 CInternetFile *pFile = NULL;
 CFtpConnection *pFtp = NULL;
 CString strServerName;

 pFtp = session.GetFtpConnection ("ftp.tripod.com", "my_username",
"my_password");
 pFile = pFtp->OpenFile ((LPCTSTR) "hello.txt");
/* The above statement returns an error that gives m_pStream as NULL
(ASSERTION FAILURE)*/

CString csA;
pFile->ReadString (csA);
MessageBox (csA);
pFile->ReadString (csA);
MessageBox (csA);

pFile->Close ();
delete pFile;
///////////////////////////////////////////////////////////////////////////
/* MY CODE FOR READING ENDS HERE */
///////////////////////////////////////////////////////////////////////////

Quote:
}

void CMyDlg::OnWrite ()
{
////////////////////////////////////////////////////////////////////////////
///
/* MY CODE FOR WRITING STARTS HERE */
////////////////////////////////////////////////////////////////////////////
///

CInternetSession session("My Session");
CInternetFile *pFile = NULL;
CFtpConnection *pFtp = NULL;

 char szUser[100];

pFtp = session.GetFtpConnection ("ftp.tripod.com", "my_username",
"my_password");
pFile = pFtp->OpenFile ((LPCTSTR) "hello.txt", GENERIC_WRITE);

SOCKADDR_IN sin;

strcpy (szUser, (LPCTSTR) "Hello");

pFile.WriteString ((LPCTSTR) szUser);
pFile->WriteString ((LPCTSTR) "\n");
pFile->WriteString ((LPCTSTR) szIP);
pFile->WriteString ((LPCTSTR) "\n");

pFile.Close ();

delete pFile;
///////////////////////////////////////////////////////////////////////////
/* MY CODE FOR WRITING ENDS HERE */
///////////////////////////////////////////////////////////////////////////

Quote:
}

///////////////////////////////////////////////////////////////////////////
/*        WHAT THE HELL IS  WRONG ?      */
/* I've been braking my head over this all night  */
///////////////////////////////////////////////////////////////////////////

Thank you soooooooooooo much.
You  guys are *so* wonderful ... ;-)

Michelle Stone.



Thu, 21 Aug 2003 12:02:34 GMT  
 Sample code (bit long) CInternetFile::ReadString and CInternetFile

Quote:
> Hi !!!!!!!!!!!!!!!!!!

> I used the following code to read and write data to my TRIPOD server: What
> is wrong here? This is being used for storing a user's name and his/her IP
> address.
> Thanks a zzzzzzziiiillllion ...

> void CMyDlg::OnRead ()
> {

////////////////////////////////////////////////////////////////////////////
Quote:
> ///
> /* MY CODE FOR READING STARTS HERE */

////////////////////////////////////////////////////////////////////////////

Quote:
> ///
> char szUser[100];
> char szIP[100];

>  CInternetSession session("My Session");
>  CInternetFile *pFile = NULL;
>  CFtpConnection *pFtp = NULL;
>  CString strServerName;

>  pFtp = session.GetFtpConnection ("ftp.tripod.com", "my_username",
> "my_password");
>  pFile = pFtp->OpenFile ((LPCTSTR) "hello.txt");
> /* The above statement returns an error that gives m_pStream as NULL
> (ASSERTION FAILURE)*/

My MSDN shows that GetFtpConnection has 2 more parameters, the port number
and a passive mode flag. You can probably ignore the flag, but the port
number seems to default to some invalid code. Try this:
pFtp = session.GetFtpConnection("ftp.tripod.com", "user", "pass", 21);

Quote:

> CString csA;
> pFile->ReadString (csA);
> MessageBox (csA);
> pFile->ReadString (csA);
> MessageBox (csA);

> pFile->Close ();
> delete pFile;

///////////////////////////////////////////////////////////////////////////
Quote:
> /* MY CODE FOR READING ENDS HERE */

///////////////////////////////////////////////////////////////////////////
Quote:
> }

> void CMyDlg::OnWrite ()
> {

////////////////////////////////////////////////////////////////////////////
Quote:
> ///
> /* MY CODE FOR WRITING STARTS HERE */

////////////////////////////////////////////////////////////////////////////
Quote:
> ///

> CInternetSession session("My Session");
> CInternetFile *pFile = NULL;
> CFtpConnection *pFtp = NULL;

>  char szUser[100];

> pFtp = session.GetFtpConnection ("ftp.tripod.com", "my_username",
> "my_password");
> pFile = pFtp->OpenFile ((LPCTSTR) "hello.txt", GENERIC_WRITE);

> SOCKADDR_IN sin;

> strcpy (szUser, (LPCTSTR) "Hello");

> pFile.WriteString ((LPCTSTR) szUser);
> pFile->WriteString ((LPCTSTR) "\n");
> pFile->WriteString ((LPCTSTR) szIP);
> pFile->WriteString ((LPCTSTR) "\n");

> pFile.Close ();

> delete pFile;

///////////////////////////////////////////////////////////////////////////
Quote:
> /* MY CODE FOR WRITING ENDS HERE */

///////////////////////////////////////////////////////////////////////////
Quote:
> }

///////////////////////////////////////////////////////////////////////////
Quote:
> /*        WHAT THE HELL IS  WRONG ?      */
> /* I've been braking my head over this all night  */

///////////////////////////////////////////////////////////////////////////

- Show quoted text -

Quote:

> Thank you soooooooooooo much.
> You  guys are *so* wonderful ... ;-)

> Michelle Stone.



Thu, 21 Aug 2003 12:20:23 GMT  
 Sample code (bit long) CInternetFile::ReadString and CInternetFile
The FTPTREE sample program uses GetFtpConnection as in the following:

m_pFtpConnection = m_pInetSession->GetFtpConnection(strServerName);


Quote:


> > Hi !!!!!!!!!!!!!!!!!!

> > I used the following code to read and write data to my TRIPOD server:
What
> > is wrong here? This is being used for storing a user's name and his/her
IP
> > address.
> > Thanks a zzzzzzziiiillllion ...

> > void CMyDlg::OnRead ()
> > {

////////////////////////////////////////////////////////////////////////////
Quote:
> > ///
> > /* MY CODE FOR READING STARTS HERE */

////////////////////////////////////////////////////////////////////////////
Quote:
> > ///
> > char szUser[100];
> > char szIP[100];

> >  CInternetSession session("My Session");
> >  CInternetFile *pFile = NULL;
> >  CFtpConnection *pFtp = NULL;
> >  CString strServerName;

> >  pFtp = session.GetFtpConnection ("ftp.tripod.com", "my_username",
> > "my_password");
> >  pFile = pFtp->OpenFile ((LPCTSTR) "hello.txt");
> > /* The above statement returns an error that gives m_pStream as NULL
> > (ASSERTION FAILURE)*/

> My MSDN shows that GetFtpConnection has 2 more parameters, the port number
> and a passive mode flag. You can probably ignore the flag, but the port
> number seems to default to some invalid code. Try this:
> pFtp = session.GetFtpConnection("ftp.tripod.com", "user", "pass", 21);

> > CString csA;
> > pFile->ReadString (csA);
> > MessageBox (csA);
> > pFile->ReadString (csA);
> > MessageBox (csA);

> > pFile->Close ();
> > delete pFile;

///////////////////////////////////////////////////////////////////////////
Quote:
> > /* MY CODE FOR READING ENDS HERE */

///////////////////////////////////////////////////////////////////////////
Quote:
> > }

> > void CMyDlg::OnWrite ()
> > {

////////////////////////////////////////////////////////////////////////////
Quote:
> > ///
> > /* MY CODE FOR WRITING STARTS HERE */

////////////////////////////////////////////////////////////////////////////

- Show quoted text -

Quote:
> > ///

> > CInternetSession session("My Session");
> > CInternetFile *pFile = NULL;
> > CFtpConnection *pFtp = NULL;

> >  char szUser[100];

> > pFtp = session.GetFtpConnection ("ftp.tripod.com", "my_username",
> > "my_password");
> > pFile = pFtp->OpenFile ((LPCTSTR) "hello.txt", GENERIC_WRITE);

> > SOCKADDR_IN sin;

> > strcpy (szUser, (LPCTSTR) "Hello");

> > pFile.WriteString ((LPCTSTR) szUser);
> > pFile->WriteString ((LPCTSTR) "\n");
> > pFile->WriteString ((LPCTSTR) szIP);
> > pFile->WriteString ((LPCTSTR) "\n");

> > pFile.Close ();

> > delete pFile;

///////////////////////////////////////////////////////////////////////////
Quote:
> > /* MY CODE FOR WRITING ENDS HERE */

///////////////////////////////////////////////////////////////////////////
Quote:
> > }

///////////////////////////////////////////////////////////////////////////
Quote:
> > /*        WHAT THE HELL IS  WRONG ?      */
> > /* I've been braking my head over this all night  */

///////////////////////////////////////////////////////////////////////////

- Show quoted text -

Quote:

> > Thank you soooooooooooo much.
> > You  guys are *so* wonderful ... ;-)

> > Michelle Stone.



Thu, 21 Aug 2003 14:11:41 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Sample code (bit long) CInternetFile::ReadString and CInternetFile

2. CInternetFile::ReadString strange behaviour

3. CInternetFile::ReadString() help !!!

4. CInternetFile::Read( ) problem

5. Wrting in READ mode? CInternetFile::WriteString ()

6. appending to a CInternetFile

7. Using GENERIC_WRITE, ASSERT in CInternetFile::WriteString()

8. CInternetFile/CHttpFile has no valid FILE* or file handle

9. Need help with CInternetFile::Write

10. Help with CInternetFile::Seek

11. CInternetFile Question

12. Weird CInternetFile problem

 

 
Powered by phpBB® Forum Software