Android Tutorial Android SMB / CIFS tutorial

The SMB library allows you to access Microsoft Windows Network file system.
You can read more information about this protocol here: Server Message Block - Wikipedia, the free encyclopedia

SMB can be used to upload or download files from Windows shared folders.
This library wraps JCIFS library: JCIFS

Before starting with your own solution it is recommended to download an existing SMB client such as AndSMB: https://play.google.com/store/apps/details?id=lysesoft.andsmb and get it working. There are several configurations that may prevent a SMB client from working properly.

If you are using Windows 7 you may want to allow access without an existing Windows account:

Go to Advanced Sharing Settings and choose Turn off password protection.

SS-2012-04-23_11.39.04.png


As with any network operations, all the operations are done in the background. An event will be raised when the operation completes.

For example to list all files and directories we can use a code such as:
B4X:
Sub Process_Globals
   Dim SMB1 As SMB
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
   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

The Url can include all kinds of parameters. See this page for more information: JCIFS API

The library is available here: http://www.b4x.com/forum/additional-libraries-official-updates/17180-smb-library.html
 

gudino jose luis

Active Member
Licensed User
Longtime User
Thanks for the reply,
if I'm handling the event.

But this solved
what I did is that username and password leave it blank
and create a user "everyone" with full privileges on the shared folder
thank you
 

soltypio

Member
Licensed User
Longtime User
The SMB library wasn't updated in v1.92. Make sure that there are no connection issues.

The NTLM protocol is used with the username and password.

If so, can this method be used to authenticate in Windows domain to acces a web service (by sending GET request with HttpUtils2) which is based on NTLM protected server?

Piotr
 
Last edited:

soltypio

Member
Licensed User
Longtime User
Last edited:

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Hello,
how do I get the list of all directories into a server path?
 

akb

Member
Licensed User
Longtime User
I'm very new here. I've only just purchased B4A so sorry if this is an obvoius question.
Where can I download the SMB library?
 

akb

Member
Licensed User
Longtime User
Thanks for the quick reply. I had already downloaded that but I didn't read the Readme.txt file that came with it. I have now moved the SMB.jar and SMB.xml files into the library folder so am a step closer.
Thanks again.
 

Mario González

Member
Licensed User
Hola buenas noches, reciban un cordial saludo desde Monterrey, México. Disculpen la molestia, por más que he intentado hacer funcionar el código del ejemplo no me ha sido posible, serían tan amables en ayudarme, de antemano gracias...
 

DonManfred

Expert
Licensed User
Longtime User
1. You should always create a NEW Thread in the QUESTIONS forum for any question you have.
2. The Questionsforum is in the English part of the forum so you should post your questions in English. You can add a spanish text to the question too.

As an alternative you can post your question in the Spanish forum if you just want to use spanish.
 

patatonj

Member
Licensed User
Longtime User
The SMB library allows you to access Microsoft Windows Network file system.
You can read more information about this protocol here: Server Message Block - Wikipedia, the free encyclopedia

SMB can be used to upload or download files from Windows shared folders.
This library wraps JCIFS library: JCIFS

Before starting with your own solution it is recommended to download an existing SMB client such as AndSMB: https://play.google.com/store/apps/details?id=lysesoft.andsmb and get it working. There are several configurations that may prevent a SMB client from working properly.

If you are using Windows 7 you may want to allow access without an existing Windows account:

Go to Advanced Sharing Settings and choose Turn off password protection.

SS-2012-04-23_11.39.04.png


As with any network operations, all the operations are done in the background. An event will be raised when the operation completes.

For example to list all files and directories we can use a code such as:
B4X:
Sub Process_Globals
   Dim SMB1 As SMB
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
   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

The Url can include all kinds of parameters. See this page for more information: JCIFS API

The library is available here: http://www.b4x.com/forum/additional-libraries-official-updates/17180-smb-library.html


Hi Erel and sorry for the question.....
i need to copy some files from Pc to my device and viceversa, this library still work on Win10 pro?

Thanks in advance
 
Top