Android Question jcifs-ng Client SMB

tribunaantonino

Member
Licensed User
Ciao DonManfred , sto cercando di usare la tua libreria con un accesso anonimo
credentials.Domain = ""
credentials.Username = ""
credentials.Password = ""
credentials.Share = "smb: // SERVER / Users / Public /"
L'evento SMBClient_Resource viene chiamato e mi riporta vero, OK, smb: // SERVER / Users / Public /, smb: // SERVER / Users / Public /
ma quando richiedo la lista dei file mi da come errore jcifs.smb.SmbAuthException: accesso negato.
Ho provato ad usare l'applicazione file manager con le stesse credenziali e la lista viene eseguita correttamente.
E' possibile utilizzare la libreria con accesso anonimo?
 
Last edited:

DonManfred

Expert
Licensed User
??? This is the english part of the Forum.

Please write english here. Alternatively you can ask your Question in Italian in the Italian Forum. But do not expect to get any answer there from me as i do not speak your Language.
 
Upvote 0

tribunaantonino

Member
Licensed User
Ok, my english is not good ... but I will try to do the translation.
I'm trying to use your library with anonymous access by entering these credentials:
credentials.Domain = ""
credentials.Username = ""
credentials.Password = ""
credentials.Share = "smb: // SERVER / Users / Public /"
The SMBClient_Resource event is called
SMBClient_Resource(true,OK,smb://SERVER/Users/Public/prova,smb://SERVER/Users/Public/prova)
but when I ask for the list of files i get the error jcifs.smb.SmbAuthException: Access is denied.
I entered the same credentials in the File Manager + app and I can view the list of files in the public folder of windows 10.

I thank you in advance for the reply.
 
Last edited:
Upvote 0

tribunaantonino

Member
Licensed User
as a test project I used jcifs-ng-Example.b4a

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout1")
credentials.Initialize
credentials.Domain = ""
credentials.Username = ""
credentials.Password = ""
credentials.Share = "smb://SERVER/Users/Public/prova/"

edt_Domain.Text = credentials.Domain
edt_Username.Text = credentials.Username
edt_Password.Text = credentials.Password
edt_Share.Text = credentials.Share

Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result Then

End If
Log(ListFolders(File.DirRootExternal))
End Sub

the error is:

Domain =
Username =
Password =
Share = smb://SERVER/Users/Public/prova/
SMBClient_Resource(true,OK,smb://SERVER/Users/Public/prova/,smb://SERVER/Users/Public/prova/)
SMBClient_Resource(smb://SERVER/Users/Public/prova/, smb://SERVER/Users/Public/prova/)
CanonicalPath = smb://SERVER/Users/Public/prova/
CanonicalUncPath = smb://SERVER/Users/Public/prova/
jcifs.smb.SmbAuthException: Access is denied.
at jcifs.smb.SmbTransportImpl.checkStatus2(SmbTransportImpl.java:1410)
at jcifs.smb.SmbTransportImpl.checkStatus(SmbTransportImpl.java:1552)
at jcifs.smb.SmbTransportImpl.sendrecv(SmbTransportImpl.java:1007)
at jcifs.smb.SmbTransportImpl.send(SmbTransportImpl.java:1523)
at jcifs.smb.SmbSessionImpl.sessionSetupSMB2(SmbSessionImpl.java:549)
at jcifs.smb.SmbSessionImpl.sessionSetup(SmbSessionImpl.java:483)
at jcifs.smb.SmbSessionImpl.send(SmbSessionImpl.java:369)
at jcifs.smb.SmbSessionImpl.send(SmbSessionImpl.java:347)
at jcifs.smb.SmbTreeImpl.treeConnect(SmbTreeImpl.java:607)
at jcifs.smb.SmbTreeConnection.connectTree(SmbTreeConnection.java:619)
at jcifs.smb.SmbTreeConnection.connectHost(SmbTreeConnection.java:563)
at jcifs.smb.SmbTreeConnection.connectHost(SmbTreeConnection.java:484)
at jcifs.smb.SmbTreeConnection.connect(SmbTreeConnection.java:460)
at jcifs.smb.SmbTreeConnection.connectWrapException(SmbTreeConnection.java:421)
at jcifs.smb.SmbFile.ensureTreeConnected(SmbFile.java:551)
at jcifs.smb.SmbEnumerationUtil.doEnum(SmbEnumerationUtil.java:225)
at jcifs.smb.SmbEnumerationUtil.listFiles(SmbEnumerationUtil.java:283)
at jcifs.smb.SmbFile.listFiles(SmbFile.java:1192)
at de.donmanfred.SMBClientwrapper$11.run(SMBClientwrapper.java:461)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
 
Upvote 0

DonManfred

Expert
Licensed User
1. Please use code tags when posting code!
2. I don´t see how you are accessing smb to raise the error.
3. Is the path you mentioned a valid SMB-Resource?

Looks like you want access any folder on the PC but not a Networkshare

I give you another chance to edit your post and give all needed Informations to me to help you.
 
Upvote 0

tribunaantonino

Member
Licensed User
Thanks a lot Manfred!

Sorry ... I'm not an expert on the forum and I will try to be clearer. I used the File Manager app with anonymous access to view the windows 10 public folder files and the folders and files are displayed correctly therefore the SMB resource is valid.
I used your example project jcifs-ng-Example.b4a changing only the credentials on the sub main.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    credentials.Initialize
    
    credentials.Domain = ""
    credentials.Username = ""
    credentials.Password = ""
    credentials.Share = "smb://SERVER/Users/Public/prova"

    edt_Domain.Text = credentials.Domain
    edt_Username.Text = credentials.Username
    edt_Password.Text = credentials.Password
    edt_Share.Text = credentials.Share
    
    Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result Then
        
    End If
    Log(ListFolders(File.DirRootExternal))
End Sub

.

By studying your project I believe that list of files is called in the starter module in the SMBClient_Resource event

B4X:
Sub SMBClient_Resource(success As Boolean, smbobjres As Object,smbobj As Object, info As String)
    Log($"SMBClient_Resource(${success},${info},${smbobjres},${smbobj})"$)
    If smbobjres <> Null And smbobj <> Null And info = "OK" Then
        Dim smbResource As SMBResource = smbobjres
        glRes = smbResource
        
        Dim smbfile As SMBFile = smbobj

        Log($"SMBClient_Resource(${smbResource}, ${smbfile})"$)
        Log($"CanonicalPath = ${smbfile.CanonicalPath}"$)
        Log($"CanonicalUncPath = ${smbfile.CanonicalUncPath}"$)
        

        'Dim flist As List = smbfile.listFiles
        'Log($"ListFiles2(res,"*.tif")"$)
        'jcifs.listFiles2(smbfile,"*.tif")




        
    '    cmbClient.GetResourcefromUrl("smb://192.168.192.168/SMBTest/")
    '    wait for SMBClient_Resource(smbobjres2 As Object,smbobj2 As Object)
    '    Log("GithubShare found...")
    '    github = smbobjres2
    '    Dim SMBTestOrdner As SMBFile = smbobj2
    '    Log($"${SMBTestOrdner.CanonicalPath}"$)
    '    Log($"ListFiles2(res)"$)
        smbClient.listFiles(smbResource)
    End If
 
Upvote 0

DonManfred

Expert
Licensed User
I can not say anything about File Manager and what it does, which protocol it uses.

I just know that the jcif-ns smb Library needs a real Networdshare to work. It is not a Fileaccess for any windows pcs folder.

I am not able to get any Filelist without create a share for a specific folder first.

Try setting up a real share on the pc and try to access this share.
 
Upvote 0

tribunaantonino

Member
Licensed User
I entered the username and password at the start of the PC and now I can get the list of files in the public folder.
I believe that the jcifs-ng library cannot be accessed as an anonymous user.
 
Upvote 0

DonManfred

Expert
Licensed User
I'm trying to use this library to copy file from shared folder in my Pc but do not know how can i do.
have you some example, please?
1. It is a mistake top post in old threads. ALWAYS create a NEW THREAD for your questions/issues.
2. For B4A there is an example in the library thread.
 
Upvote 0

DonManfred

Expert
Licensed User
have you some example, please?
See my answer here:
 
Upvote 0
Top