I am using Delphi 2010 and Indy 10 that ships with it. The MemStream is a TMemoryStream and it contains a file downloaded from a website.
IdTrivialFTP1 := TIdTrivialFTP.Create(nil);
try
IdTrivialFtp1.Name := 'IdTrivialFTP1';
IdTrivialFTP1.Host := 'my-tftp-server-name.contoso.com';
IdTrivialFTP1.Port := 69;
IdTrivialFTP1.ReceiveTimeout := 4000;
MemStream.Position := 0;
IdTrivialFTP1.Put(MemStream, sFileName);
finally
FreeAndNil(IdTrivialFTP1);
end;
Whenever I run this code, I get the error:
Project TestProject.exe raised exception class ERangeError with message 'Range check error'.
I've been doing quite a bit of google-ing to understand this error, but I'm currently at a loss. I've also seen only 1 example of how to perform a TFTP PUT using Indy components.
Any ideas?
UPDATE: If I trace into the error a bit, I find that the error is being thrown from within "IdTrivialFTP.pas" on line 272:
CurrentDataBlk := WordToStr(GStack.HostToNetwork(Word(TFTP_DATA)))
+ WordToStr(GStack.HostToNetwork(BlockCtr));
For clarity, here is the context of that code:
if BlockCtr > PrevBlockCtr then
begin
DataLen := IndyMin(BufferSize - hdrsize, SourceStream.Size - SourceStream.Position);
SetLength(CurrentDataBlk, DataLen + hdrsize);
CurrentDataBlk := WordToStr(GStack.HostToNetwork(Word(TFTP_DATA))) + WordToStr(GStack.HostToNetwork(BlockCtr));
SetLength(CurrentDataBlk, DataLen + hdrsize);
//SourceStream.ReadBuffer(CurrentDataBlk[hdrsize+1], DataLen);
DoWork(wmWrite, DataLen);
TerminateTransfer := DataLen < BufferSize - hdrsize;
PrevBlockCtr := BlockCtr;
end;
Send(FPeerIP, FPeerPort, CurrentDataBlk);
until False; { repeat }