B4J Question how to use smb

gezueb

Active Member
Licensed User
Longtime User
Hi, I want to copy a file with b4j from/to a NAS storage where user and password are required to access.
I tried this little program from the tutorial:

B4X:
Sub Process_Globals
    Dim SMB1 As SMB
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
    Log ("Hello")
'    If FirstTime Then
        SMB1.Initialize("SMB1")
'    End If

    SMB1.ListFiles("smb://USER-PC/Users/Public/", "")
End Sub

Sub SMB1_ListCompleted(Url As String, Success As Boolean, Entries() As SMBFile)
    If Not(Success) Then
        Log(LastException)
    Else
        For i = 0 To Entries.Length - 1
            Log("*****************")
            Log(Entries(i).Name)
            Log(Entries(i).Directory)
            Log(DateTime.Date(Entries(i).LastModified))
            Log(Entries(i).Parent)
            Log(Entries(i).Size)
        Next
    End If
End Sub

It compiles allright, but the code does nothing. Ok, the template path does not exist, but it not even logs "Hello".
Thanks for advice!
 

JordiCP

Expert
Licensed User
Longtime User
The starting code in B4J must be placed in AppStart. Activity_Create(..) will never be called, that's only in Android.
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
Thank you , Jordi, thats one of these copy/paste things! I will post the code here when I got it working.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Please note that the SMB Library does not Support SMB2 Protocol.
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
Thanks for the advice. And what would support SMB2 if any? I am working in a W10 environment, so SMB2 seems compulsory. All I want to do is copy a file to a wd mycloud home NAS programmatically and repetively. The wd app looses connection when W10 is restarted (e.g. after an update) so the log on must be done manually.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
You could assign the WD drive a drive letter in Windows ( mine is Z) then simply write to z:/....
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
Yes,I know. The problem is that this works only after starting the WD app and entering the credentials there. Then the z: path is visible and open until Windows is shut down. It survives the energy saving mode of a pc but not shutdown. This means that all pc's that should access the Home cloud must be connected to the NAS by a discrete user entry after (re-)start . I would have preferred it if my b4j app would do that automatically when using centralized data.
It did work in the good old days but Windows 10 shut this door.
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
OK, I got it working. The public drive of WD MYCLOUD home can be read/write accessed without password from b4j using a statement like:
File.Copy(Pathstring,FileName,"//MYCLOUD-XXXYYY/Public",Filename) or any other file operation.
Please note the // instead of the \\ backslash as noted in the wd support documents "how to map a wd network drive".
XXXYYY are the last 6 digits of the serial number. This is NOT the code printed on the quick install card and at the bottom of the label on the device, but from the group of characters preceded by "S/N" on same label.
No requirements of SMB or any credentials.
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
Another tip: Copying files over WLAN to/from NAS is much slower than on a local pc. If the copied or read files will be used immediately in a b4j program, file.CopyAsync with a waitfor on success should be used, otherwise the file might not be ready for further processing, which causes errors of course.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Thanks for the advice. And what would support SMB2 if any? I am working in a W10 environment, so SMB2 seems compulsory. All I want to do is copy a file to a wd mycloud home NAS programmatically and repetively. The wd app looses connection when W10 is restarted (e.g. after an update) so the log on must be done manually.
FYI, to my knowledge there is no support for SMB2. If you find it let me know.
 
Upvote 0
Top