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
 

peternmb

Well-Known Member
Licensed User
Longtime User
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
Know anybody a way to do this with registry-settings or a script?
 

walterf25

Expert
Licensed User
Longtime User
File Size Limit

Hello Erel, do you know if there's a limit as far as a file size to Upload or Download, the reason i ask is because i tried to upload a video file around 46mB from my sd card to my pc and i can see the file icon in my computer directory but it doesn't seem to upload it fully.

Thanks any hints will be greatly appreciated!
 

jake

Member
Licensed User
Longtime User
Should I be able to use an AVD device and SMB to get to files on my laptop? I'm having some troubles connecting. Am getting an unknown host exception.
 

entolium

Member
Licensed User
Longtime User
I'm using this library (is great). For my application, the raise event when list files "is a problem". I would like to change "raise event" with the entries to "return" entries, but the creating libraries tutorial is another world for me. Any idea?

Thank you and sorry for my very bad english.
 

entolium

Member
Licensed User
Longtime User
Thank you Erel,

I can wait to network communication. I will try to change the SMB.jar code, it's my only way out. Any help will be appreciated :D.
 

entolium

Member
Licensed User
Longtime User
I compiled de SMB source with eclipse without change the code, but when I use it in B4A, the application is stopped in the device :(.
My computer (and java 7) is 64 bit. Is this a problem?
If I use the original SMB.jar, the application works fine.
 

entolium

Member
Licensed User
Longtime User
Good news!! Its working!!!
I checked "Add directory entries" in export menu in eclipse and now works fine.

- ListFiles return a SMBFile array
- Delete, Copy, Rename and MakeDir returns true or false
- FreeDiskSpace return the size

Now, I can continue with my application. I'm happy!!!!! :D
 

FBernard

New Member
Hi, I'm new here. I registered because I wanted to try this library. Do I have to buy a license to be able to actually download it ?
 

gudino jose luis

Active Member
Licensed User
Longtime User
hi Erel
I have a problem with the SMB function, I have an application that uses this function you first use it with XP without problems, then with W7 and it worked perfect, but now does not work correctly with W8, the network is properly configured to share files, and have all the privileges of the user.
any suggestions?
regards
 

gudino jose luis

Active Member
Licensed User
Longtime User
I am showing the contents of a folder with a jpg file. in xp and w7 shown correctly.
simply does not display the contents of the folder but not gives an error

one question; I should do with jcifs.jar library, and where should I include
 
Last edited:
Top