Android - Using SMB server without root access

As your original question still isn't answered and I wondered the same, here's the answer.

Short answer: No, without root it's not possible to run an SMB server using the default ports so that it's found by Windows PCs.

Long answer: SMB either runs on ports 137-139 (UDP and TCP) using NetBIOS or on newer systems (from Windows Vista onwards) directly on TCP port 445 where in the latter case computer names are resolved by the LLMNR (Link-local Multicast Name Resolution) protocol which runs on UDP port 5355. Why is this important? Apps not running as root can't bind to unprivileged ports (<1024). It's possible to use alternative ports for SMB but Windows is hard-wired to just listen to the default ones. So I guess if you use Linux or a separate SMB client for Windows which allows to connect to a server with a custom port number it's probably possible. But it's not really a straight-forward way.


While it may not be possible to run an SMB server without root or using port forwarding, it is possible to run a WebDAV server without root for a similar effect.

Setting up an Android WebDAV server

On my stock Nexus 7, I installed WebDAV Server, opened it, clicked on the start button and was immediately able to see my /storage/sdcard folder in my web browser at the URL displayed by the application, i.e. http://192.168.x.y:8080

Note that with WebDAV, you also have the option of selecting Root (/) or DCIM as well as SdCard as the WebDAV root.

Using the WebDAV server through Windows Explorer

I then mapped http://192.168.x.y:8080 as a network drive in Windows Explorer and could the access the contents of my storage drive, just as if I was connected via MTP, but through a drive letter.

Sadly, this solution is incredibly slow.

Every directory change takes between 6 and 20 seconds, as does accessing most files. Once a file is accessed though, it transfers at a reasonable speed (copying a single 42MB file in Windows Explorer took around 60 seconds, so 700KB/s).

Thus WebDAV via Windows Explorer is Ok for downloading a few large files whose location you know, but browsing or syncing a whole device this way isn't quick. I synced 1.75GB of data in around 6000 files and 400 directories and it took 10 hours, i.e. around 50KB/s or 10 files/dirs per minute on average.

Using the WebDAV server through Windows command line

Even from the command line, each directory listing takes 5-6 seconds, as does any file access. Copying the same 42MB file from the command line took around 20 seconds, so around 2.1MB/s.

Using the WebDAV server through a web browser

The fastest option for WebDAV is to use your web browser though, directly through the URL given. Changing directory rarely takes more than a second and downloading the same 42MB file from the web browser took around 12 seconds, so around 3.6MB/s.

The downside of using the web browser is that it only shows the date (no size or type) and makes no distinction between files and directories so if a file doesn't have an extension (or a directory does) then it may not be obvious if clicking on a link will take you to another web page (for a directory) or start a download (for a file).

Caveats

  • By default, Windows limits the size of WebDAV downloads to 50000000 bytes (47.6MB), though this can be changed through a registry hack (FileSizeLimitInBytes in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WebClient\Parameters) if you know what you are doing.

  • WebDAV access is not secure. Even if you set a password on the WebDAV share, the connection is still http not https, so it is not encrypted. Only use WebDAV on a secure wifi network and certainly don't enable the WebDAV server while you are in an internet cafe or other unsecured wifi.


The issue is not the samba server, but the fact that Windows can access a samba share only on port 445, and on a non-rooted android a normal App can't listen on port 445.

But you can overcome this with some TCP port-mapping:

  1. Install a samba server on your android, and make it listen on a port like 7777
  2. Install a TCP port-forwarding software somewhere (I installed it on a virtualPC)
  3. Setup the portmapping software to listen for connections on port 445, and forward the connections to your android on port 7777
  4. Now you can access the shared folder on this virtualPC, and you'll get the data from the samba server installed on android (trough the portmapping)

I've described all the steps in detail here on my blog http://techforpassion.blogspot.it/2013/12/android-how-to-share-folder-over-wifi.html

I've tried different samba server, and the only free app that works in this configuration is called Samba Server