Home


Delphi - Indy FTP-Upload mit Fortschrittsanzeige

{
  Author  : http://developer.luckie-online.de
  Date    : 2005-03-22
  License : PUBLIC DOMAIN
}


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, IdBaseComponent, IdComponent,
  IdTCPConnection, IdTCPClient, IdFTP, IdAntiFreezeBase, IdAntiFreeze;

type
  TForm1 = class(TForm)
    IdFTP1: TIdFTP;
    OpenDialog1: TOpenDialog;
    edtServer: TEdit;
    edtRemDir: TEdit;
    edtPW: TEdit;
    Button1: TButton;
    ProgressBar1: TProgressBar;
    edtFile: TEdit;
    Button2: TButton;
    edtUser: TEdit;
    StatusBar1: TStatusBar;
    IdAntiFreeze1: TIdAntiFreeze;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure IdFTP1Status(ASender: TObject; const AStatus: TIdStatus;
      const AStatusText: String);
    procedure IdFTP1WorkBegin(Sender: TObject; AWorkMode: TWorkMode;
      const AWorkCountMax: Integer);
    procedure IdFTP1WorkEnd(Sender: TObject; AWorkMode: TWorkMode);
    procedure IdFTP1Work(Sender: TObject; AWorkMode: TWorkMode;
      const AWorkCount: Integer);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button2Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
    edtFile.Text := OpenDialog1.FileName;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  IdFTP1.Host := edtServer.Text;
  IdFtp1.Username := edtUser.Text;
  IdFTP1.Password := edtPW.Text;
  IdFTP1.Connect;
  IdFTP1.ChangeDir(edtRemDir.Text);
  IdFTP1.Put(edtFile.Text, ExtractFilename(edtFile.Text));
  IdFTP1.Disconnect;
end;

procedure TForm1.IdFTP1Status(ASender: TObject; const AStatus: TIdStatus;
  const AStatusText: String);
begin
  Statusbar1.SimpleText := AStatusText;
end;

procedure TForm1.IdFTP1WorkBegin(Sender: TObject; AWorkMode: TWorkMode;
  const AWorkCountMax: Integer);
begin
  ProgressBar1.Max := AWorkCountMax;
end;

procedure TForm1.IdFTP1WorkEnd(Sender: TObject; AWorkMode: TWorkMode);
begin
  ProgressBar1.Position := 0;
end;

procedure TForm1.IdFTP1Work(Sender: TObject; AWorkMode: TWorkMode;
  const AWorkCount: Integer);
begin
  ProgressBar1.Position := AWorkCount;
  Application.ProcessMessages;
end;

end.

2012-01-26T23:14:42 +0100