Re: Resume function not correctly download my file - WeOnlyDo Discussion board

Re: Resume function not correctly download my file (General questions)

by rossi, Monday, July 24, 2006, 11:04 (6697 days ago) @ wodDrazen

Have re-import type library and still have the same.

Basically there're only 2 main function in my program, those are Connect2FtpServer and GetFileViaFtp. Here're the detail:

function TForm1.Connect2FtpServer: boolean;
var
isConnected: boolean;
i: integer;
begin
try
try
i:= 0;
isConnected:= false;

while (not isConnected)and(i<=10) do
begin
try
MywodFtp.Hostname:= Edit3.Text;
MywodFtp.Port:= strtoint(Edit6.Text);
MywodFtp.Protocol:= ComboBox1.ItemIndex;{use 4 for implicit}
MywodFtp.Blocking:= true;
MywodFtp.Login:= Edit4.Text;
MywodFtp.Password:= Edit5.Text;

MywodFtp.Disconnect1;
if i<>0 then
begin
Sleep(1000);
memo1.Lines.Add('RESUME CONNECT #'+inttostr(i));
end;
MywodFtp.Connect1;
isConnected:= true;
except
isConnected:= false;
end;
i:= i+1;
end;
finally
result:= isConnected;
end;
except
result:= false;
end;
end;

function TForm1.GetFileViaFtp(rfname, fname: string; var err: string;
isResume: boolean): boolean;
var
i: integer;
isSuccess: boolean;
tmpFName: string;
isDownloaded: boolean;
begin
try
if Length(rfname)>0 then
if rfname[1]<>'/' then
rfname:= '/'+ rfname;
isResume:= false;

if rfname[Length(rfname)]<>'/' then
begin
Result:= true;
i:=0;
isSuccess:= false;
while (not isSuccess)and(i<10) do
begin
try
if i=0 then
begin
MywodFtp.Resume:= false;
MywodFtp.GetFile(fname,rfname);
end else
begin
Sleep(1000);
isResume:= isResume;
MywodFtp.Resume:= true;
Memo1.Lines.Add('RESUME #'+inttostr(i+1));
MywodFtp.GetFile(fname,rfname);
end;

isSuccess:= true;
except
on e: Exception do
begin
isSuccess:= false;
err:= e.Message;
if e.Message='Cannot execute, not yet connected' then
Connect2FtpServer;
if (e.Message='Requested action not taken. File unavailable (e.g., file not found, no access)') then
isSuccess:= true
else
isSuccess:= false;
end;
end;
i:= i+1;
end;
result:= isSuccess;
end else
begin
Result:= true;
end;
except
on E: Exception do
begin
result:= false;
err:= e.Message;
end;
end;
end;


procedure TForm1.Button1Click(Sender: TObject);
var
err: string;
begin
if Connect2FtpServer then
begin {use true to resume mode}
if GetFileViaFtp(Edit1.Text,Edit2.Text,err,CheckBox1.Checked) then
begin
MessageDlg('Download process finished',mtConfirmation,[mbOK],0);
end else
begin
MessageDlg('Download process finished',mtError,[mbOK],0);
end;
end else
begin
MessageDlg('Can not connect to FTPServer',mtError,[mbOK],0);
end;
end;

----- finished ---

Is there something missed with that code?


Complete thread: