0

I have this code that works perfectly on Windows, but when running the application on Android, the connection to FTP is successful, but when writing the file, the app stays paused without doing anything.

It should be noted that on the FTP server, it appears that I am loading the file as in the image:

image

This is my code:

procedure TForm1.Button1Click(Sender: TObject);
begin
//  testClever;
//  exit;

    IdFTP:=TIdFTP.Create(nil);
    IdSSLIO:=TIdSSLIOHandlerSocketOpenSSL.Create(nil);
      IdFTP.Disconnect();
        {$ifdef mswindows}
          idopensslsetlibpath('C:\Users\karol.campos\Desktop\FTPSExample\SSL');
        {$endif}
        {$ifdef android}
          idopensslsetlibpath(TPath.GetDocumentsPath);
        {$endif}
        IdSSLIO.SSLOptions.Method:=TIdSSLVersion.sslvSSLv23;
        IdSSLIO.PassThrough:=true;
        IdFTP.IOHandler:=IdSSLIO;
        IdFTP.ListenTimeout:=0;
        IdFTP.ReadTimeout:=0;
        IdFTP.TransferTimeout:=0;
        IdFTP.Passive:=true;
        IdFTP.UseTLS:=TIdUseTLS.utUseExplicitTLS;
        IdFTP.DataPortProtection:=TIdFTPDataPortSecurity.ftpdpsPrivate;

        IdFTP.Host := '(ip_ftp)';
        IdFTP.Username := '(user)';
        IdFTP.Password := '(pass)';
        
        try
        IdFTP.Connect;

        try
            {$ifdef mswindows}
              IdFTP.Put('D:\SeLogro.txt','SeLogro.txt',false);
            {$endif}
            {$ifdef android}
              IdFTP.Put('storage/emulated/0/SeLogro.txt','SeLogro.txt',false);
            {$endif}
              ShowMessage('Ready!');
            finally
              IdFTP.Disconnect();

            end;
        except
        on E : Exception do
         begin
           ShowMessage('Exception class name = '+E.ClassName);
           ShowMessage('Exception message = '+E.Message);
         end;
        end;
end;

I found a similar question, but the code is in Java, will it be possible to do it in Delphi 10.3?

android ftp file tranfer over explicit TLS

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Kenneth
  • 101
  • 1
  • If your question is about 10.3, why did you also tag it with Berlin and Seattle? – Ken White Dec 06 '22 at 01:05
  • 1
    The code looks fine, so the problem has to be outside of the code. It sounds like the data connection is being blocked. One thing I would suggest is assigning a non-infinite value to the `TIdFTP.ConnectTimeout` property, which is used for both the command connection and the data connections. – Remy Lebeau Dec 06 '22 at 01:26
  • As per [RFC 7151 §3.1](https://datatracker.ietf.org/doc/html/rfc7151#section-3.1) the `HOST` command has a bad syntax: square brackets indicate an IPv6 address, but your screenshot shows the client is sending an IPv4 address. So either it's an incomplete IPv6 address, or the square brackets are wrong. – AmigoJack Dec 06 '22 at 02:21
  • Is delphi syntax, single quotes (') are used, The value 0 was assigned in TIdFTP.ConnectTimeout but the problem persists. – Kenneth Dec 06 '22 at 18:11
  • How could I interpret this code? JAVA FTPSClient mFtps = new FTPSClient(); mFtps.setTrustManager(TrustManagerUtils.getAcceptAllTrustManager()); for delhpi, is it possible? – Kenneth Dec 06 '22 at 18:17
  • @AmigoJack `TIdFTP` sends square brackets in `HOST` only for valid IPv6 addresses – Remy Lebeau Dec 07 '22 at 13:39
  • @Kenneth setting `ConnectTimeout` to 0 is the same as setting it to infinite. Try a real timeout value, like 10+ seconds. Also, you really should not be using `IdSSLIO.SSLOptions.Method := sslvSSLv23` at all, you should use the `SSLVersions` property instead, eg: `IdSSLIO.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];` – Remy Lebeau Dec 07 '22 at 13:41
  • @RemyLebeau Then the screenshot is fake, as a valid/complete IPv6 address having an IPv4 portion must be at least `::10.106.12.111`. – AmigoJack Dec 07 '22 at 14:39
  • I've tried everything and it still hasn't worked. If someone could share a code that works with explicit TLS, it would be a great help. – Kenneth Dec 07 '22 at 20:27

0 Answers0