Android Question Filetransfer from Android device to Windows Server via WLAN usi

DirkH

Member
I'm new to B4A and tried with the help of ChatGPT try to built a Android APP that allows to transfer Photos from a Smartphone to a Windows Server via WLAN. The core function does not work. I tried to use jcifs-ngV0.32 but I am not able to start it. the error message is:
Fehler: java.lang.ClassNotFoundException: jcifs$CIFSContext
(ClassNotFoundException) java.lang.ClassNotFoundException: jcifs$CIFSContext
I have the impression that ChatGPT relied on this Library and it does not work and doesn't admit that we are in the middle of nowhere.

this is the sub:
Sub KopiereVomSmartphoneZuSMB(p_Map As Map, zielKey As String)
Log("KopiereVomSmartphoneZuSMB: Start, Key=" & zielKey)
Try
Dim quellPfad As String = p_Map.Get("Quellpfad")
Dim zielPfad As String = ""
Dim benutzer As String = p_Map.GetDefault("SMBUser", "")
Dim passwort As String = p_Map.GetDefault("SMBPass", "")

If p_Map.ContainsKey(zielKey) = False Then
ToastMessageShow("Zielpfad nicht gefunden: " & zielKey, True)
Return
End If

Dim eintrag As Map = p_Map.Get(zielKey)
zielPfad = eintrag.Get("Pfad")

If quellPfad = "" Or zielPfad = "" Then
ToastMessageShow("Quell- oder Zielpfad fehlt.", True)
Return
End If

Log("Quelle: " & quellPfad)
Log("Ziel: " & zielPfad)

' Authentifizierung
Dim jcifs As JavaObject
jcifs.InitializeStatic("jcifs.CIFSContext")

Dim baseContext As JavaObject = jcifs.RunMethod("getSystemInstance", Null)
Dim NtlmAuth As JavaObject
NtlmAuth.InitializeNewInstance("jcifs.smb.NtlmPasswordAuthenticator", Array(benutzer, passwort))
Dim authContext As JavaObject = baseContext.RunMethodJO("withCredentials", Array(NtlmAuth))

' Ziel vorbereiten
Dim zielFolder As JavaObject
zielFolder.InitializeNewInstance("jcifs.smb.SmbFile", Array(zielPfad, authContext))
If zielFolder.RunMethod("exists", Null) = False Then
zielFolder.RunMethod("mkdir", Null)
End If

' Lokale Dateien lesen
Dim files As List = File.ListFiles(quellPfad)
If files.IsInitialized Then
Log("Gefundene Dateien:")
For Each f As String In files
Log(f)
Next
Else
Log("Liste ist nicht initialisiert")
End If
If files.IsInitialized = False Then
ToastMessageShow("Quellverzeichnis nicht lesbar.", True)
Return
End If

For Each dateiname As String In files
If File.IsDirectory(quellPfad, dateiname) = False Then
Log("Kopiere: " & dateiname)

Dim lokalInput As InputStream = File.OpenInput(quellPfad, dateiname)
Dim zielDatei As JavaObject
zielDatei.InitializeNewInstance("jcifs.smb.SmbFile", Array(zielPfad & "/" & dateiname, authContext))
Dim smbOutput As OutputStream = zielDatei.RunMethod("getOutputStream", Null)

CopyStream(lokalInput, smbOutput)
End If
Next

ToastMessageShow("Kopiervorgang abgeschlossen.", False)
Catch
Log("Fehler: " & LastException.Message)
Log(LastException) ' Gibt Stacktrace
ToastMessageShow("Fehler beim Kopieren vom Smartphone.", True)
End Try
End Sub

I controlled, several times, that the Libraries are at the right place and have the right names. It is introduced:
#AdditionalJar: jcifs-ng-smb-client.jar

My question: Is there any possibility to bring this project to a happy end, or should I start from scratch using another technique.

Dirk
 

DirkH

Member
I will! I wasn't able to find a button to edit the original post. The title I wrote seems to have disappeared and be substituted with an automatically generated and not meaningful title.
Is there anyone using jcifs-ngV0.32 successfully and willing to help?
Dirk
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
there is a sort of etiquette here in the forum. you should try to see how things work.
john naylor has already mentioned using code tags so that we can read your code.
fixing chatgpt's code is not really fair, especially - as you say - chatgpt "... doesn't admit that we are in the
middle of nowhere." that is, thanks to chatgpt, you are in the middle of nowhere. if you want to know how
to use third party libraries, there are examples here. that is the question you should be asking.

the important part of your project - the part which is missing - is how you merged b4a with the third
party library (about which we may know absolutely nothing).

as a courtesy to a new user, i've looked up jcifs. i downloaded the latest release and found a simple
example for reference.

here is an example of how you would connect with a third party library:
B4X:
#AdditionalJar: jcifs-1.3.19             ' IMPORTANT

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Dim jcifs As JavaObject                  ' IMPORTANT
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")

    File.Copy(File.DirAssets,"copy.txt",File.DirInternal,"copy.txt")                ' just for test compilation purposes
    Try
        Dim outfile As String = "smb://" & File.Combine(File.Dirinternal,"copy.txt")
        jcifs.InitializeNewInstance("jcifs.smb.SmbFile",Array(outfile))                          ' IMPORTANT
    Catch
        Log(LastException)
    End Try
End Sub

obviously, this is an incomplete example, but it compiles and runs. that is to say, there is no classnotfound error. you were looking for a different class, but the principles are the same. i would have highlighted important statements, but the "code" tags prevent that. so i've marked them as "IMPORTANT" so you can check to see if what you have done resembles them. when i looked for jcifs-ngV0.32, i was quickly led to the version that i ultimately downloaded. (i assume you know to save the library to your additional libraries folder (NOT b4a's core libraries folder).
 
Upvote 0

DirkH

Member
Thank you for unblocking my developing process. I went back to the documentation to better understand the IDE and how to integrate jar files. To know, that there would be a human willing to help me if needed was vital to get this project done.
Thank you again.
Dirk
 
Upvote 0
Top