type MyFTPThread =
Class(TThread)
private
res: TStringList;
Description, action:
string;
state: boolean;
connected: boolean;
max: Double;
FTP: TIdFTP;
procedure sync(descr:
string; atend: boolean; ac:
string);
procedure updateVLC();
procedure FTPWork(ASender: TObject; AWorkMode: TWorkMode; AWorkCount: Integer);
procedure FTPWorkBegin(ASender: TObject; AWorkMode: TWorkMode; AWorkCountMax: Integer);
protected
procedure Execute;
override;
public
upload, download, clear, abort: boolean;
server, user, password:
string;
uploadname, downloadname:
string;
procedure initialize;
end;
implementation
uses OC_F1;
procedure MyFTPThread.Execute;
begin
res := TStringList.Create;
state := false;
action := '
-';
initialize;
end;
procedure MyFTPThread.initialize;
var
cnt: integer;
begin
sync('
Sequence started'#9#9'
@ ' + TimeToStr(now), false, '
_');
FTP := TIdFTP.Create();
FTP.Host := server;
FTP.Username := user;
FTP.Password := password;
FTP.OnWork := FTPWork;
// <-- Zuweisung der onWork-Prozedure auf meine eigene. Die Argumente müssen gleich sein!!!
FTP.OnWorkBegin := FTPWorkBegin;
// <-- Dasselbe für OnWorkBegin...
FTP.Connect;
if FTP.Connected
then
begin
if download
then
begin
...
end;
if upload
then
begin
...
end;
if clear
then
begin
...
end;
end;
FTP.Free;
end;
procedure MyFTPThread.updateVLC();
begin
Form1.updateVLC(res, Description, state, action);
end;
procedure MyFTPThread.FTPWork(ASender: TObject; AWorkMode: TWorkMode;
AWorkCount: Integer);
begin
if max > 0
then
begin
Form1.updatePROG(AWorkCount, max);
// Bei mir wird beim Download keine Maximalgröße der Datei übertragen. Deswegen setze ich bei
end;
// Downloads die Größe noch in der Downloadroutine mit FTP.GetSize (o.Ä.).
if abort
then
begin
FTP.Abort;
download := false;
upload := false;
abort := false;
end;
end;
procedure MyFTPThread.FTPWorkBegin(ASender: TObject; AWorkMode: TWorkMode;
AWorkCountMax: Integer);
begin
if AWorkMode = wmWrite
then // Wie oben beschrieben nur bei Uploads zu verwenden...
max := AWorkCountMax;
end;
end.