Re: Problem with TIdFTP->Get()

Giganews Newsgroups
Subject: Re: Problem with TIdFTP->Get()
Posted by:  Remy Lebeau (TeamB) (
Date: Sat, 29 Nov 2003

"virtek" <virte…> wrote in message

> TFileStream *Stream = new TFileStream("",fmCreate);
> Stream->Seek(10000);

That is meaningless.  You opened the file using fmCreate.  If the file does
not exist, it is created with 0 bytes.  If the file does exist, it is
truncated to 0 bytes.  Either way, there is nothing available to seek.

Besides, that is not the correct way to request the download start at a
given offset anyway.  You need to send the server a "REST" command before
downloading the file.  Since your stream is 0 bytes, TIdFTP cannot determine
whether to issue the command for you, so you will just have to issue the
command manually, ie:

    if( IdFTP1->ResumeSupported() )
        IdFTP1->Quote("REST 10000");

> The problem is that it downloads data until the end of file

As well it should.  The FTP protocol has no means of specifying byte ranges
to download.  It starts the download at offset 0, or the specified offset if
"REST" is used, and then always returns the full data after that point.
There is no way to stop the download early, except to close the connection
once you receive the desired amount of bytes.  Given Indy's architecture,
that is not an easy thing to accomplish precisely, unless you write your own
custom TStream class to keep close tabs on the amount of data being written
to the stream.

> and ends up with the entire size of file, while it suppose to be only part
of it...

For what you ask, FTP is not the best protocol to use to begin with.  If
possible, you might want to look at using HTTP v1.1 instead, it supports
downloading partial files at specific offsets and ranges.



In response to

Problem with TIdFTP->Get() posted by virtek on Sat, 29 Nov 2003