Android Question FTP doesn't work over 4G, only Wifi

adriano.freitas

Active Member
Among the functions of the application I'm developing is one that connects to an FTP server and sends the database (.db) to it. Afterwards, it takes this database again (a remote backup).

Everything works perfect though, just over wifi. If I'm on the street only with a 4G connection, it doesn't work. Generates an error.

Does anyone know what can it be?
 

JohnC

Expert
Licensed User
Longtime User
What error does it generate?

Please post lines from event log panel in IDE.
 
Last edited:
Upvote 0

adriano.freitas

Active Member
What error does it generate?

Please post lines from event log panel in IDE.

The difficulty is even in having access to the log, since the failure only occurs using the 4G connection. When I turn off the Wifi to be able to test on 4G, I don't have the debug on my computer.
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Everything works perfect though, just over wifi. If I'm on the street only with a 4G connection, it doesn't work. Generates an error.
Is you FTP server at your home or in a internet host?
If it's at home, are you able to access your FTP server from outside? Have you try it with an FTP client (i.e. Filezilla) to check if you need to open ports in your router?
 
Upvote 0

adriano.freitas

Active Member
Is you FTP server at your home or in a internet host?
If it's at home, are you able to access your FTP server from outside? Have you try it with an FTP client (i.e. Filezilla) to check if you need to open ports in your router?
The FTP server is an external host service. Testing with 4g through other applications (Solid Explorer etc) works, only with what I'm doing in B4A that doesn't.
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
I am already using passive mode. Is any permission required to use mobile data? Do I need to put something on the Manifest?

From this thread, not sure if it applies to FTP connections

- 28 - Non-ssl (non-https) communication is not permitted by default. It can be enabled in B4A v9+ by adding this line to the manifest editor:
B4X:
CreateResourceFromFile(Macro, Core.NetworkClearText)
 
Upvote 0

adriano.freitas

Active Member
Hi guys! I solved it through an example I found on the forum about something else, but it had a code to use FTP.

I'll leave the solution here in case anyone needs it. I must emphasize that I do not understand what this class that is used does and why it works on wifi but not on 4 g without it. Anyway, solve it!

B4X:
    Dim ftp As FTP   
    Dim ctm As CustomTrustManager      ' <<<<<<<<<<< This
    ctm.InitializeAcceptAll
    ftp.Initialize("ftp", "ftpserver", 21, "login", "password")
    ftp.PassiveMode = True
    ftp.UseSSLExplicit = True
    ftp.SetCustomSSLTrustManager(ctm)  ' <<<<<<<<<<< This
    ftp.UploadFile (File.DirAssets, "smile.jpg", False, "smile.jpg")
 
Upvote 0
Top