Android Question FTP and Adroid 8 or 9

AlpVir

Well-Known Member
Licensed User
Longtime User
The following code works perfectly with Android 5 but not with Android 8 or 9
B4X:
File.WriteString(File.DirRootExternal,"msg2.txt","test")
ftp.Initialize("FTP", Host, 21, Username,Password)
ftp.UploadFile(File.DirRootexternal,"msg2.txt", True,  IndirizzoFTP & "/msg2.txt")

I tried using FileProvider, without success
B4X:
Dim FileName As String
FileName="msg2.txt"
ftp.Initialize("FTP", Host, 21, Username,Password)
File.Copy(File.DirRootExternal, FileName, Starter.Provider.SharedFolder, FileName)
ftp.UploadFile(File.DirRootexternal,Starter.Provider.GetFileUri(FileName), True, IndirizzoFTP & "/msg2.txt")

I add that FileProvider also uses it in another part of the app and works perfectly.
B4X:
 ' WhatsApp
        Dim FileName As String = NomeImmagine
        File.Copy(File.DirRootExternal, FileName, Starter.Provider.SharedFolder, FileName) 
        '----
        i.Initialize(i.ACTION_SEND, "")
        i.PutExtra("android.intent.extra.TEXT", "Orario " & Titolo)
        i.SetType("text/plain")
        i.PutExtra("android.intent.extra.STREAM", Starter.Provider.GetFileUri(FileName))
        i.SetType("image/*")
        Dim jo As JavaObject = i
        jo.RunMethod("setPackage", Array("com.whatsapp"))
   
            StartActivity(i)
How to solve?
Thanks in advance
 

JohnC

Expert
Licensed User
Longtime User
What I would do first is use a file explorer app and make sure that the msg2.txt file actually exists in the expected directory.

That would at least help narrow down the problem.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Also, do you have access to the log file on the FTP server you are trying to upload to? Maybe it can give a clue of whats going wrong.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
a simple "Log(File.Exists...) should be useful and enough

before the uploading

When I'm troubleshooting a problem, I prefer to use an alternative method to verify something important, instead of trusting the same app (that is also giving me the error) if something is correct or not
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
When I'm troubleshooting a problem, I prefer to use an alternative method to verify something important, instead of trusting the same app (that is also giving me the error) if something is correct or not
But in this case you could explore wrong directories (or different from those used by the app), while executing the log (file.exists...) when it is useful, you will be sure of what is going to happen.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
But in this case you could explore wrong directories (or different from those used by the app), while executing the log (file.exists...) when it is useful, you will be sure of what is going to happen.
It's just the way I troubleshoot - everybody has their own methods.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Just for kicks and giggles....when you are getting this issue on an Android 8 device, are you running in debug mode?

If so, try ALL my suggestions while in release mode and see if it works.

It shouldn't make a difference, but from time to time I do find that debug mode has a few quirks.
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
As suggested by JohnC (whom I thank!) for some strange reason compiling in release mode the code now works; before I always worked in debug mode.
Thanks again !
B4X:
Dim Shd As String
Shd=GetSharedDirectory
File.WriteString(Shd,"msg2.txt",S)
ftp.Initialize("FTP", Host, 21, Username,Password)
ftp.PassiveMode=True
ftp.UseSSL=False
ftp.UploadFile(Shd,"msg2.txt", True, IndirizzoFTP & "/" & "msg2.txt")
ftp.Close
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…