Link to home
Get AccessLog in
Avatar of hidrau
hidrauFlag for Brazil

asked on

Use the idFtp event in runtime

Hi Guys,

The idFtp has an important event that gets the results, I don't know how to set / use the event when I create the idFtp in runtime. I need to
an example for it.  Below you can see my code and use it to give me an example.

Thanks a lot

  Function RunFTP( FtpServidor ,  FtpUsuario, FtpSenha, FtpPorta,  FtpAutentica, FtpCaminhoUpload, FtpCaminhoResposta: String): Boolean;

  Result := True

  if EstaVazio(FtpServidor) or EstaVazio( FtpUsuario ) or EstaVazio( FtpSenha ) or  EstaVazio( FtpAutentica ) or
     EstaVazio( FtpPorta )  {or EstaVazio( SmtpCaminhoUpload ) or EstaVazio( SmpCaminhoResposta )} then Begin
     ShowMessage('As configurações de FTP não estão completas no parceiro: ' + CodCad);
     Result := False;
     Exit;
  End;


  if FtpAutentica = '1' then
     FtpAut  := true
  else
     FtpAut  := false;


  IdFTP1 := TIdFTP.Create();
  IdFTP1.Disconnect;

  IdFTP1.Host     := FtpServidor;
  idFTP1.DirectoryListing.DirectoryName:= FtpCaminhoUpload;
  IdFTP1.Port     := Strtoint(FtpPorta);
  IdFTP1.Username := FtpUsuario;
  IdFTP1.Password := FtpSenha;
  IdFTP1.Passive  := FtpAut;

  try
     IdFTP1.Connect;
  except
     IdFTP1.Disconnect;
     IdFTP1.Connect;
     Result := False;
     Exit;
  end;

  BarraRotina('UP',Carquivo+iif(Tipo = 'Upload',' Envio ',' Recebimento ')+' de Arquivo '+Carquivo,0,0);

  Try
    Try
      if Tipo = 'Upload' then begin
         IdFTP1.Put (cArquivo, FtpCaminhoUpload+Carquivo, true);
      end else if Tipo = 'Download' then begin
                  IdFTP1.Get ( FtpCaminhoResposta+Carquivo, Carquivo, true,false);
      end else if Tipo = 'Delete' then begin
                  IdFTP1.delete ( FtpCaminhoUpload+Carquivo);
      end;
    Except
      Result := false
    End;
  Finally
    BarraRotina('UPC','Arquivo '+Carquivo+iif(Tipo = 'Upload',' Enviado ',' Recebido ')+' com sucesso',0,0);
  End;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Link to home
membership
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access
Avatar of hidrau

ASKER

THANKS A LOT FOR YOUR HELP
Avatar of hidrau

ASKER

THANKS