
procedure TFClienteHTTP.BDescargarClick(Sender: TObject);
begin
  HTTPGetText(URL.Text, Pagina.Lines);
end;

function HttpGetBinary(const URL: string; const Response: TStream): Boolean;
function HttpPostBinary(const URL: string; const Data: TStream): Boolean;
function HttpPostURL(const URL, URLData: string; const Data: TStream): Boolean;
function HttpPostFile(const URL, FieldName, FileName: string; const Data: TStream; const ResultData: TStrings): Boolean;

procedure TFClienteTFTP.BDescargarClick(Sender: TObject);
var
  Cliente: TTFTPSend;
begin
  // Creamos el cliente
  Cliente := TTFTPSend.Create;

  // Establecemos los parámetros de conexión
  Cliente.TargetHost := Servidor.Text;
  Cliente.TargetPort := Puerto.Text;

  // ¿Podemos descargar el archivo?
  if Cliente.RecvFile(Descargar.Text) then
  begin
    // Lo guardamos a disco
    Cliente.Data.SaveToFile(ExtractFilePath(Application.ExeName) + Descargar.Text);
    EMensajeDescarga.Caption := 'OK';
    EMensajeDescarga.Font.Color := clGreen;
  end
  else
  begin
    EMensajeDescarga.Caption := 'ERROR: ' + Cliente.ErrorString;
    EMensajeDescarga.Font.Color := clMaroon;
  end;

  EMensajeDescarga.Visible := True;

  // Liberamos el cliente
  Cliente.Free;
end;

procedure TFClienteTFTP.BExaminarClick(Sender: TObject);
begin
  if AbrirArchivo.Execute then
    Subir.Text := AbrirArchivo.FileName;
end;

procedure TFClienteTFTP.BSubirClick(Sender: TObject);
var
  Cliente: TTFTPSend;
begin
  // Comprobamos si el usuario ha seleccionado el archivo
  if Subir.Text = '' then
  begin
    Application.MessageBox('Seleccione el archivo que desea subir al servidor.',
      'Atención', MB_ICONEXCLAMATION);
    ActiveControl := Subir;
    Exit;
  end;

  // Comprobamos si el archivo a subir existe
  if not FileExists(Subir.Text) then
  begin
    Application.MessageBox('El archivo que intenta subir al servidor no existe.',
      'Atención', MB_ICONEXCLAMATION);
    ActiveControl := Subir;
    Exit;
  end;

  // Creamos el cliente TFTP
  Cliente := TTFTPSend.Create;

  // Establecemos los parámetros de conexión
  Cliente.TargetHost := Servidor.Text;
  Cliente.TargetPort := Puerto.Text;

  // Intentamos subir el archivo
  Cliente.Data.LoadFromFile(Subir.Text);

  if Cliente.SendFile(ExtractFileName(Subir.Text)) then
  begin
    EMensajeSubida.Caption := 'OK';
    EMensajeSubida.Font.Color := clGreen;
  end
  else
  begin
    EMensajeSubida.Caption := 'ERROR: ' + Cliente.ErrorString;
    EMensajeSubida.Font.Color := clMaroon;
  end;

  EMensajeSubida.Visible := True;

  // Liberamos el cliente
  Cliente.Free;
end;
