Re: [twsocket] Overbyte ICS FTP upload with progress bar

2015-03-06 Thread MMG Admin
Thank you for the guidelines!

2015-02-22 16:32 GMT+02:00 Lester Clayton :

> I've writen an FTP client that previously used OnFtpProgress, and can
> confirm that it's called a tremendous amount of times, and in my case
> caused my client application to hit 100% CPU as a result.  The way I've
> implemented it in the past is to create another FTP Client class derived
> from ICS FTPClient, with an added timer which is turned on at the start of
> the transfer, and off at the end of the transfer, and every time the timer
> is fired (at intervals of say, 1000 ms), it updates the progress bar.
>
> Hope that helps with an efficient implementation.
>
> Lester
>
> On 22/02/2015 15:27, Angus Robertson - Magenta Systems Ltd wrote:
>
>> procedure TForm2.FtpProgress(Sender: TObject; Count: Int64;
>>>var Abort: Boolean);
>>> begin
>>> ProgressBar.Position := Count;
>>> end;
>>>
>> Correct concept, but you also need to set the ProgressBar Min and Max
>> properties to indicate how much progress has been made.
>>
>> The FTP event simply returns a count of the number of bytes transferred,
>> which
>> might be zero to several billion, so Min should be set to zero and Max to
>> the
>> size of the file being uploaded, before the upload starts.  Harder for
>> downloads where you need to know the size of the file first.
>>
>> Also, this event will typically be called dozens of times per second on a
>> fast
>> internet connection, and updating the screen is time consuming so can
>> slow down
>> the transfer speed, and the change may be invisible.
>>
>> So you generally put more intelligence in the progress function to update
>> no
>> more than once every one or more seconds or when there is a substantial
>> change,
>> like 1 to 5%.
>>
>> Angus
>>
>>
> --
> To unsubscribe or change your settings for TWSocket mailing list
> please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
> Visit our website at http://www.overbyte.be
>
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Overbyte ICS FTP upload with progress bar

2015-02-22 Thread Angus Robertson - Magenta Systems Ltd
> Client class derived from ICS FTPClient, with an added timer which 
> is turned on at the start of the transfer, and off at the end of 
> the transfer, and every time the timer is fired (at intervals of 
> say, 1000 ms), it updates the progress bar.

A timer itself is high overhead, another hidden window and is not necessary
where an event is already being called regularly.  

Much easier to use GetTickCount which returns milliseconds since Windows booted,
store a value and then check against until a duration as passed, there is an
ICS function IcsCalcTickDiff that does this, TMagFtp updates progress every
2,000 ticks, two seconds. 

TWsocket has a Counter property that includes ConnectTick when a connection
started so you can easily check how long it's been going.

Angus


-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Overbyte ICS FTP upload with progress bar

2015-02-22 Thread Lester Clayton
I've writen an FTP client that previously used OnFtpProgress, and can 
confirm that it's called a tremendous amount of times, and in my case 
caused my client application to hit 100% CPU as a result.  The way I've 
implemented it in the past is to create another FTP Client class derived 
from ICS FTPClient, with an added timer which is turned on at the start 
of the transfer, and off at the end of the transfer, and every time the 
timer is fired (at intervals of say, 1000 ms), it updates the progress bar.


Hope that helps with an efficient implementation.

Lester

On 22/02/2015 15:27, Angus Robertson - Magenta Systems Ltd wrote:

procedure TForm2.FtpProgress(Sender: TObject; Count: Int64;
   var Abort: Boolean);
begin
ProgressBar.Position := Count;
end;

Correct concept, but you also need to set the ProgressBar Min and Max
properties to indicate how much progress has been made.

The FTP event simply returns a count of the number of bytes transferred, which
might be zero to several billion, so Min should be set to zero and Max to the
size of the file being uploaded, before the upload starts.  Harder for
downloads where you need to know the size of the file first.

Also, this event will typically be called dozens of times per second on a fast
internet connection, and updating the screen is time consuming so can slow down
the transfer speed, and the change may be invisible.

So you generally put more intelligence in the progress function to update no
more than once every one or more seconds or when there is a substantial change,
like 1 to 5%.

Angus



--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Overbyte ICS FTP upload with progress bar

2015-02-22 Thread Angus Robertson - Magenta Systems Ltd
> I'm using the ICS Overbyte FTP for uploading a file. I want to 
> display a progressbar and a speed indicator 

I've commented on the progress bar in a separate reply, calculating speed
simply involves timing how long it takes to transfer so many bytes (using
GetTickCount) and doing the sums on the remaining bytes, which you can only do
after the first 5 or 10 seconds when you have some data.  

> after the upload is completed i want to delete the file 

You have no error handling here so you don't know the upload completed
successfully, it may fail because the file already exists on the FTP server or
fails part way through.  Windows has a DeleteFile function.

If you want to do this properly, use the free Magenta Systems File Transfer
Components, and TMagFtp which is a high level version of Tftpclient that
handles multiple file, and includes a progress for single and multiple files. 

http://www.magsys.co.uk/delphi/magxfer.asp

Angus

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Overbyte ICS FTP upload with progress bar

2015-02-22 Thread Angus Robertson - Magenta Systems Ltd
> procedure TForm2.FtpProgress(Sender: TObject; Count: Int64;
>   var Abort: Boolean);
> begin
>ProgressBar.Position := Count;
> end;

Correct concept, but you also need to set the ProgressBar Min and Max
properties to indicate how much progress has been made.  

The FTP event simply returns a count of the number of bytes transferred, which
might be zero to several billion, so Min should be set to zero and Max to the
size of the file being uploaded, before the upload starts.  Harder for
downloads where you need to know the size of the file first.

Also, this event will typically be called dozens of times per second on a fast
internet connection, and updating the screen is time consuming so can slow down
the transfer speed, and the change may be invisible. 

So you generally put more intelligence in the progress function to update no
more than once every one or more seconds or when there is a substantial change,
like 1 to 5%.

Angus

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be