Re: About file transferring

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Maverick (Maverick_at_maverick.com)
Date: 02/23/05


Date: Wed, 23 Feb 2005 09:43:03 +0800

I'am using the latter one, that is to download the file into a memory buffer
and then save it to disk. Here is some of the code.
///////////////////////////////////////////////////////////////////////////
BOOL CFtpSockClient::GetFile( CString csRemoteFile, CString csLocalFile )
{
 if( !OpenDataChannel() )
  return FALSE;

 CString csCommand = "RETR " + csRemoteFile;
 BOOL bRetVal = SendCommand( csCommand );
 GetResponse();
 if( !bRetVal || GetErrorCode() != DATA_OK )
 {
  m_SockSrvr.Close();
  return FALSE;
 }

 CAsyncSocket DataSocket;
 // accept inbound data connection from server
 if( ! m_SockSrvr.Accept( DataSocket ) )
 {
  SetErrorCode ( ERR_SOCK_ACCEPT );
  DataSocket.Close();
  m_SockSrvr.Close();
  return FALSE;
 }

 CFile cfDataFile;

 if( ! cfDataFile.Open( csLocalFile, CFile::modeCreate |
CFile::modeWrite ) )
 {
  SetErrorCode( ERR_SOCK_LOCFILE );
  return FALSE;
 }

 char szBuffer[ MAX_BUFFER ];
 int nNumBytesRead;
 CString csLocFileBuffer;
 while ( TRUE )
 {
  memset( szBuffer, '\0', MAX_BUFFER );

  nNumBytesRead = DataSocket.Receive( szBuffer, MAX_BUFFER - 1 );

  if( ! nNumBytesRead || nNumBytesRead == SOCKET_ERROR )
   break; // ( EOF || network error )

  csLocFileBuffer += szBuffer;
 }

 cfDataFile.Write( csLocFileBuffer, csLocFileBuffer.GetLength() );

 DataSocket.Close();

 m_SockSrvr.Close();

 cfDataFile.Close();

 GetResponse();

 if( GetErrorCode() != GET_OK )
  return FALSE;

 return TRUE;
}
////////////////////////////////////////////////////////////////////////////
////

How to getting the file in pieces? You mean save each piece to disk, then
merge them after receiving? But how to merge files? Is there any related
APIs?

maverick

"Paul G. Tobey [eMVP]" <ptobey no spam AT no instrument no spam DOT com> д
ÈëÓʼþ news:e$gZTfPGFHA.2676@TK2MSFTNGP12.phx.gbl...
> I'd suspect a problem with storage on the CE device, rather than network
> communications. Are you getting the file in small pieces, rather than
> trying to download it all into a memory buffer and then save it to disk?
> That should be pretty reliable and I don't recall having any problems with
> it.
>
> It's worthwhile to apply all available QFEs to your OS, though, in case
> something has been fixed by MS.
>
> Paul T.
>
> "Maverick" <Maverick@maverick.com> wrote in message
> news:e0sM4QMGFHA.2296@TK2MSFTNGP15.phx.gbl...
> > Hi, all
> >
> > I am working on CE.net 4.2 and my device is a CEPC. From my device I
> > tried
> > to get a large file(about 1MB) on a remote ftp server. But I alwayse get
a
> > smaller corrupted one. For example, the file size on ftp server is 400k,
> > but
> > what I get is only 300K. If the file is smaller than 100K, I would get
the
> > file without any error. I had tried using raw Socket and MFC's CSocket,
> > also I had tried to add more memory on the CEPC(now is 256MB), and I had
> > tried put the device and ftp server in a same LAN(so network is very
> > fast).
> > However, no matter what I tried, I alwayse get the same result. I also
> > tried
> > the demo on
> > http://www.codeguru.com/Cpp/W-P/ce/networking/article.php/c3533/, which
> > got
> > the same result.
> >
> > Does anybody have done such thing on CE.net before? Or is there any
> > alternative ways to stay clear of the damned Socket?
> >
> > maverick
> >
> >
> >
>
>



Relevant Pages

  • Re: Can not get past the welcome screen
    ... What I meant by reformatting is taking my ... to my machine to download my files and such, it will be a great loss. ... "Boot Menu" is the choice that you want. ... CD drive and press "Enter" The computer should now boot off of the disk. ...
    (microsoft.public.windowsxp.general)
  • RE: panda and windows xp stop error
    ... THE PROBLEM CONTINUES TO REPEAT EACH TIME PANDA INTERNET SECURITY 2008 SCANS ... THE COMPUTER CRASHES IN THE MIDDLE OF DISK C: ... You may need to reposition/reset the RAM sticks in their slots. ... Download Avast Cleaner from here: ...
    (microsoft.public.windowsxp.security_admin)
  • Re: Failure to Reinstall Windows XP
    ... to the hard disk during a standard WinXP installation. ... is a Dell, I presume you've contacted Dell Support? ... The Autorun feature on the system disk failed to download the C:I386 ...
    (microsoft.public.windowsxp.general)
  • Re: New Hard Drive vs. New Computer
    ... You can download things, and transport them ... to the broken machine via floppy, CDROM, USB stick and so on. ... The hard disk diagnostic program that your disk manufacturer has on his web site will check the disk for physical errors. ... If it fails then nothing is lost: Just do a clean installation of Windows on the new disk. ...
    (microsoft.public.windowsxp.general)
  • Re: The long-sought Harry Conover pyro files
    ... Compared with the original distribution disk, some if the junk kid pyro ... I caution everyone not to download the ... disk image from any site other the one that Bob has provided, ... wall as traditional popular selections. ...
    (rec.pyrotechnics)