Bug? Netlib 1.52 - FTP with explicit SSL and MANIFEST

MMORETTI964

Member
Licensed User
Longtime User
Hi, I think I've found a problem in the FTP net library version 1.52.
I use SSL (explicit) with a FileZilla Server to make a connection with a self-signed certificate with this code:

Sub Activity_Create(FirstTime As Boolean)
Effetipi.Initialize("Effetipi", "10.10.10.54",21, "user", "pwd")
CTM.InitializeAcceptAll
Effetipi.SetCustomSSLTrustManager(CTM)
Effetipi.PassiveMode = True
Effetipi.UseSSL=False
Effetipi.UseSSLExplicit=True
Log(Effetipi.IsInitialized)
Effetipi.SendCommand("PWD","")
End Sub


Sub Effetipi_CommandCompleted (Command As String, Success As Boolean, ReplyCode As Int, ReplyString As String)
Effetipi.CloseNow()
Msgbox("finito","")
End Sub

When using closenow...
android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.close(OpenSSLSocketImpl.java:908)
at org.apache.commons.net.SocketClient.closeQuietly(SocketClient.java:309)
at org.apache.commons.net.SocketClient.disconnect(SocketClient.java:298)
at org.apache.commons.net.ftp.FTP.disconnect(FTP.java:434)
at org.apache.commons.net.ftp.FTPClient.disconnect(FTPClient.java:843)
at anywheresoftware.b4a.net.FTPWrapper.CloseNow(FTPWrapper.java:434)
at com.palmosoft.primaprova.main._effetipi_commandcompleted(main.java:377)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
at anywheresoftware.b4a.BA$3.run(BA.java:319)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
at dalvik.system.NativeStart.main(Native Method)

The problem occurred on the line with closenow but only in release or debug legacy (works in debug rapid!) and only with this manifest directive:
android:targetSdkVersion="14"

If you remove the targetSdkVersion directive or debug in rapid mode this problem vanishes.

Attached the project.

Maurizio
 

Attachments

  • PrimaProva.zip
    37.8 KB · Views: 204

MMORETTI964

Member
Licensed User
Longtime User
In my mind CloseNow was better to delete all pending events to retry.

In effect when I had to retry I need to re-initialize the same object and I thought using CloseNow before was a better way to "destroy" or "clean" the object.

In my program I have a second IP for backup and I make retries, so I reuse immediately the same object for another connection.

If I use Close can I reuse - reinitialize immediately the same object?

Have you an idea why I have this exception (only in legacy & release, only when targetSdkVersion included in manifest?)

Thank you in advance.

Maurizio
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
CloseNow should normally not be used. It will break any unfinished tasks. You should instead use Close.

You can dim the variable again and initialize it.

Have you an idea why I have this exception (only in legacy & release, only when targetSdkVersion included in manifest?)
Yes. It is related to a change in Android 4.
 

MMORETTI964

Member
Licensed User
Longtime User
As I need the variable declared in the globals (because of the _completed event i need at least module scope), can I destroy and reinitialize it with this after close like the sample (code in bold)?
And the Effetipi instance is referred to the global variable even if I re-declared in the sub?

Sub Process_Globals
Private Effetipi As FTP
Private retry As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
Effetipi.Initialize("Effetipi", "10.10.10.54",21, "user", "pwd")
CTM.InitializeAcceptAll
Effetipi.SetCustomSSLTrustManager(CTM)
Effetipi.PassiveMode = True
Effetipi.UseSSL=False
Effetipi.UseSSLExplicit=True
Log(Effetipi.IsInitialized)
Effetipi.SendCommand("PWD","")
End Sub


Sub Effetipi_CommandCompleted (Command As String, Success As Boolean, ReplyCode As Int, ReplyString As String)
Effetipi.Close()
Effetipi=null
dim Effetipi as FTP

Effetipi.Initialize("Effetipi", "anotherip",21, "user", "pwd")
...
End Sub

Thank you for your patience.
Maurizio
 
Top