Article View: borland.public.cppbuilder.internet.socket
Article #1595Re: Indy 10: Send a file with TIdTCPClient
From: Remy Lebeau (TeamB)
Date: Thu, 07 Dec 2006 10:34
Date: Thu, 07 Dec 2006 10:34
64 lines
2771 bytes
2771 bytes
"David" <microges@email.it> wrote in message
news:4577d9b5@newsgroups.borland.com...
> TCPClient.IOHandler.WriteLn(FileName);
You shouldn't be sending the full file path, only the file name:
TCPClient.IOHandler.WriteLn(ExtractFileName(FileName));
> TCPClient.IOHandler.WriteFile(FileName);
Try using Write(Stream) instead.
> FStream := TFileStream.Create(NomeFile, fmCreate, fmOpenWrite);
Where and how is NomeFile assigned?
> AContext.Connection.IOHandler.LargeStream := True;
Did you set LargeStream to True on the client side?
> AContext.Connection.IOHandler.ReadStream(FStream);
By default, ReadStream() reads an integer value (an Int64 in this case
because you set LargeStream to True) specifying the number of stream bytes
being sent. However, WriteFile() does not send that value. So you are
corrupting your file transfer. If you are going to use ReadStream() like
that, then you have to call Write(Stream) on the client side instead of
WriteFile(). For example:
--- Client ---
uses
IdGlobal, IdObjs, IdSys;
var
Stream: TIdStream;
begin
Stream := TIdReadFileExclusiveStream.Create(FileName);
try
TCPClient.IOHandler.WriteLn(ExtractFileName(FileName));
TCPClient.IOHandler.LargeStream := True;
TCPClient.IOHandler.WriteStream(Stream, 0, True);
finally
Sys.FreeAndNil(Stream);
end;
end;
--- Server ---
NomeFile := 'C:\Some Folder\' +
ExtractFileName(AContext.Connection.IOHandler.ReadLn);
FStream := TIdFileCreateStream.Create(NomeFile);
try
AContext.Connection.IOHandler.LargeStream := True;
AContext.Connection.IOHandler.ReadStream(FStream);
finally
Sys.FreeAndNil(FStream);
end;
Gambit
Technical Details
Message-ID:
<4577eec9@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news3.google.com!news.germany.com!newsfeed.cw.net!cw.net!news-FFM2.ecrc.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4577d9b5@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,6fbabc84eb654d68 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.internet.socket References: <4577d9b5@newsgroups.borland.com> Subject: Re: Indy 10: Send a file with TIdTCPClient Date: Thu, 7 Dec 2006 02:34:56 -0800 Lines: 66 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 75.83.34.171 Message-ID: <4577eec9@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1165487817 75.83.34.171 (7 Dec 2006 02:36:57 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news3.google.com!news.germany.com!newsfeed.cw.net!cw.net!news-FFM2.ecrc.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail