1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ScktComp, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdFTP;
type
TForm1 = class(TForm)
Memo1: TMemo;
lister_fichiers: TButton;
Label1: TLabel;
IdFTP1: TIdFTP;
procedure lister_fichiersClick(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
APath : string;
i : integer;
implementation
{$R *.dfm}
////////////////////////////////////////////////////////////////////////////////
procedure TForm1.lister_fichiersClick(Sender: TObject);
begin
Try
with IdFTP1 do
begin
// Connexion au serveur FTP //
if not Connected then
begin
IdFTP1.Host := 'ftpperso.free.fr';
IdFTP1.Port := 21;
IdFTP1.Username := 'nomduFTP';
IdFTP1.Password := 'motdepasse';
IdFTP1.Passive := true;
IdFTP1.Connect;
IdFTP1.ChangeDir('/rep1');
end;
memo1.lines.Clear;
idftp1.List(memo1.lines,'',false); // juste nom fichiers
label1.caption := ('nombre de fichiers :'+inttostr(memo1.lines.count - 2));
if (i >= 2) then // on télécharge que s'il y a des fichiers ....
begin
for i:=2 to memo1.lines.count-1 do
begin
idftp1.get(memo1.lines[i],'c:\test\'+memo1.lines[i],true,false);
Delete( memo1.lines[i]); // efface les fichiers sur le FTP
end;
end;
end;
Except
on E: Exception do
MessageDlg( 'Erreur FTP : ' + E.Message, mtError, [mbOK], 0 );
End;
IdFTP1.Disconnect;
end;
end. |
Partager