Recent

Author Topic: lazarus android synapse40 and ftp  (Read 2230 times)

skom

  • New member
  • *
  • Posts: 9
lazarus android synapse40 and ftp
« on: July 03, 2018, 01:51:34 pm »
Hello,
I use Lazarus 1.8.0 with LAMW (laztoapk) and synapse 4.0,
I try to download from FTP and save to FTP file.
If I run applications as an android application (via "[LAMW] Bulid Android Apk and Run" FTP connection does not work, I get "Can not login" for jButton1 and "Not uploaded" for pressing jButton2.
If the same procedures (changing TButton Buttons, and "Self.GetEnvironmentDirectoryPath (dirDownloads)" on windows directories and running via Run (in windows - F9), everything works and downloads and saves files from / to FTP.
Where is my mistake that I do not work on android?

unit1.pas:

Code: Pascal  [Select][+][-]
  1. unit unit1;
  2.  
  3. //{$mode delphi}
  4. {$mode objfpc}{$H+}
  5.  
  6. interface
  7.  
  8. uses
  9.   Classes, SysUtils, AndroidWidget, Laz_And_Controls, FTPSend;
  10.  
  11.  
  12. type
  13.  
  14.   { TAndroidModule1 }
  15.  
  16.   TAndroidModule1 = class(jForm)
  17.     jButton1: jButton;
  18.     jButton2: jButton;
  19.     aFTP: TFTPSend;
  20.     procedure jButton1Click(Sender: TObject);
  21.     procedure jButton2Click(Sender: TObject);
  22.   private
  23.     {private declarations}
  24.   public
  25.     {public declarations}
  26.   end;
  27.  
  28. var
  29.   AndroidModule1: TAndroidModule1;
  30.  
  31. implementation
  32.  
  33. {$R *.lfm}
  34.  
  35.  
  36. { TAndroidModule1 }
  37.  
  38. procedure TAndroidModule1.jButton1Click(Sender: TObject);
  39. begin
  40.   what_download := 'time.txt';
  41.   try
  42.     aFTP := TFTPSend.Create;
  43.     try
  44.       aFTP.TargetHost := 'ftp.xxxx.pl';
  45.       aFTP.UserName := 'xxxx.pl';
  46.       aFTP.Password := '*****';
  47.       aFTP.BinaryMode := true;
  48.       aFTP.DirectFile := true;
  49.       aFTP.DirectFileName :=what_download;
  50.       aFTP.DirectFile := true;
  51.       if aFTP.Login then
  52.       begin
  53.         if not aFTP.RetrieveFile(Self.GetEnvironmentDirectoryPath(dirDownloads) + '/' + what_download,false) then
  54.           showmessage('Not downloaded');
  55.         aFTP.Logout;
  56.       end
  57.       else
  58.         showmessage('Can''t login');
  59.     finally
  60.       aFTP.free;
  61.     end;
  62.  
  63.   finally
  64.  
  65.   end;
  66.  
  67. end;
  68.  
  69. procedure TAndroidModule1.jButton2Click(Sender: TObject);
  70. var
  71.   Result:Boolean;
  72.   what_upload : string;
  73. begin
  74.   what_upload := 'time.txt';
  75.   Result := FtpPutFile('ftp.xxxx.pl', '21', Self.GetEnvironmentDirectoryPath(dirDownloads)+'/'+what_upload, what_upload, 'xxxx.pl', '*****');
  76.   if result then
  77.     showmessage('Uploaded')
  78.   else
  79.     showmessage('Not uploaded');
  80. end;
  81.  
  82. end.

 

TinyPortal © 2005-2018