0

how can i catch a connection exception on android when connection to FTP.

Code At the Moment :

idftp1.Host    := Servidor_ftp;
idftp1.Username:= Usuario_ftp;
idftp1.Password:= Contraseña_ftp;
Try
  idftp1.Port    := StrToInt(Puerto_ftp);
except
  idftp1.Port := 21;
End;
Try
  idftp1.Connect;
  idftp1.Passive := true;
  if Carpeta_ftp = '' then
    IdFTP1.Put( System.IOUtils.TPath.Combine(System.IOUtils.tpath.getdocumentspath,'temp.txt'), Nombre_pistola+'.txt' , False )
  else
    IdFTP1.Put( System.IOUtils.TPath.Combine(System.IOUtils.tpath.getdocumentspath,'temp.txt'), Carpeta_ftp+Nombre_pistola+'.txt', False );
  idftp1.Disconnect;
except
  ShowMessage('Hay un error con la conexion al FTP, compruebe si tiene internet y si esta bien configurado todo.');
End;

The connection works correctly when all is configured correctly (server, user, pass, port) but it could be configured incorrectly and in that case it would not connect, if i use that code with windows i get an exception after the timeout, but on android it just stays there and i get the message "Wait for app or kill app"

Thank you.

vexen
  • 345
  • 1
  • 4
  • 20
  • The code is fine as is. Indy raises exceptions on errors on Android, too. You should not be running this code on the main UI thread, though. Android does not allow network connections on the UI thread, or the UI thread being blocked for lengthy operations. – Remy Lebeau Feb 15 '19 at 16:36
  • Hello Remy, thx for the reply im sorry for the dumb question then, but do you have a link on how to make stuff on the other thread to not make it in the UI Thread? Or how would i change the component to a different thread atm got like 0.1% of android and FMX knowledge..... (had only 30 hours to make a new app in FMX without knowing anything about FMX....) Thank you! – vexen Feb 18 '19 at 08:55

0 Answers0