CInternetFile ??

   I have a file in the server, i want to read that file & then append some data to the data of that file & then write this data to that file.
  How can i do it?
  i was using Read & Write functions of this class but its giving some problems to me.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

How UR doing it what kind of site is it?
if U have a ftp site then append is not possible U have to down load it append and upload again some code sure will help us to help U
kulsmadyaAuthor Commented:
i am doing ftp...
 but when i use to read the file , it's giving error..
 i am able to write into file.. but to append , i should be reading the file first & then append & then write the file...
Yes for ftp it won't work copy the file into UR local disk append it and keep it back in Ftp server. thats the only way around
Here's code that will download a file from an FTP site, it should get you started.  Once you have the file, make the changes, then to upload, you do follow the same steps as downloading except call CFtpConnection::PutFile(LPCTSTR pstrLocalFile, LPCTSTR pstrRemoteFile, DWORD dwFlags = FTP_TRANSFER_TYPE_BINARY, DWORD dwContext = 1 );

--Good Luck

CInternetSession session;
CFtpConnection* pServer = NULL;
CInternetFile* pFile = NULL;

char sFile[] = "";
char* sPath;

// check to see if the URL is reasonable

      CString strServerName;
      CString strObject;
      CString strDir;
      CString strFile;
      int nPos;
      INTERNET_PORT nPort;
      DWORD dwServiceType;

      if (!AfxParseURL(sFile, dwServiceType, strServerName, strObject, nPort) ||
            dwServiceType != INTERNET_SERVICE_FTP)
            ASSERT(0); //bad URL                  
            return NULL;
      pServer = session.GetFtpConnection(strServerName, NAME, PASSWORD, nPort);

      nPos = strObject.ReverseFind('/');
      strDir = strObject.Left(nPos);
      strFile = strObject.Right(strObject.GetLength() - nPos -1);


      CFtpFileFind ftpFileFind(pServer);

            pFile = pServer->OpenFile(strFile);

      CFile file;
      char* sTmp;

      sTmp = (char*)malloc(_MAX_PATH);
      sPath = (char*)malloc(_MAX_PATH);

      GetTempPath( _MAX_PATH, sTmp);

      GetTempFileName(sTmp, "~xxx~", 0, sPath);

      file.Open(sPath, CFile::modeReadWrite);

      TCHAR sz[1024];
      int nCount = 0;
            nCount = pFile->Read(sz, 1023);
            file.Write(sz, nCount);
      while (nCount > 0);


catch (CInternetException* pEx)
      // catch errors from WinINet
      TCHAR szErr[1024];
      pEx->GetErrorMessage(szErr, 1024);


if (pFile != NULL)
      delete pFile;

if (pServer != NULL)
      delete pServer;


return sPath;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.