I will test a workaraound solution, as below
The B4A SFtpWrapper does not expose a method for setting the connection timeout. With an unstable mobile connection, UploadFile may remain blocked for quite a long time before returning an error.
I inspected
SFtpWrapper.class with
javap and found the following private field:
private com.jcraft.jsch.Session session;
The connectIfNeeded() method eventually calls:
Therefore, the JSch timeout can be set
after Initialize() but before UploadFile(), using Reflection and JavaObject to access the private session field:
Try
Dim r As Reflector
r.Target = sftp
Dim cls As Object = r.RunMethod("getClass")
Dim rCls As Reflector
rCls.Target = cls
Dim field As Object = rCls.RunMethod2("getDeclaredField", "session", "java.lang.String")
Dim joField As JavaObject = field joField.RunMethod("setAccessible", Array(True))
Dim session As Object = joField.RunMethod("get", Array(sftp))
If session <> Null Then
Dim joSession As JavaObject = session joSession.RunMethod("setTimeout", Array(30000))
Log("SFTP timeout set to 30 seconds.")
End If
Catch
Log("Error setting SFTP timeout: " & LastException)
End Try
The important part is that this code runs
before UploadFile(). Initialize() creates the JSch Session object, while the actual connection is established later by connectIfNeeded() when UploadFile() is called.
Tested successfully: the private Session object was retrieved and setTimeout(30000) was applied without errors.
This is a workaround rather than an official SFtpWrapper API, but it may be useful until a timeout property/method is exposed by the library.