Re: About file transferring
From: Maverick (Maverick_at_maverick.com)
Date: 02/23/05
- Next message: tennisman: "closesocket"
- Previous message: Ginny Caughey [MVP]: "Re: Binary of flat File VS CE Database ?"
- In reply to: Paul G. Tobey [eMVP]: "Re: About file transferring"
- Next in thread: Paul G. Tobey [eMVP]: "Re: About file transferring"
- Reply: Paul G. Tobey [eMVP]: "Re: About file transferring"
- Messages sorted by: [ date ] [ thread ]
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
> >
> >
> >
>
>
- Next message: tennisman: "closesocket"
- Previous message: Ginny Caughey [MVP]: "Re: Binary of flat File VS CE Database ?"
- In reply to: Paul G. Tobey [eMVP]: "Re: About file transferring"
- Next in thread: Paul G. Tobey [eMVP]: "Re: About file transferring"
- Reply: Paul G. Tobey [eMVP]: "Re: About file transferring"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|