Skip to content

Instantly share code, notes, and snippets.

@akaleeroy
Last active October 14, 2021 16:31
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save akaleeroy/a5ae8ad2e194e2bde471 to your computer and use it in GitHub Desktop.
Save akaleeroy/a5ae8ad2e194e2bde471 to your computer and use it in GitHub Desktop.
Access phone storage over WiFi with WebDAV Server for Android

Access phone storage over WiFi

Batch file to map your Android phone as network drive in Windows.

Preview of Phone.cmd usage

Requirements

Instructions

  • Put in your phone's MAC address, desired drive letter and port number
    ℹ️ If using DHCP the phone's IP can change but the script will still find it.

Usage

  • Turn on WebDAV Server on your phone
  • Run the script once to connect.
    ℹ️ Running it a second time removes the mapped drive.
    If you are using a password it will ask for it the first time, and save them in Credential Manager.

WebDAV vs. Samba Server

Samba doesn't work on Windows without a rooted Android phone.

✔️ With Samba you can navigate and transfer files faster
❌ With Samba you can't sort by Date modified and there are Thumbs.db files everywhere
With Samba you can set up Offline Files in Windows and sync your phone's data.
✔️ With Samba you can navigate the phone's filesystem even with the screen turned off.

@echo off
setlocal enabledelayedexpansion
:: EDIT -----------------------
set mac="xx-xx-xx-xx-xx-xx"
set letter="K:"
set port="36363"
:: Toggle on off by checking if drive is mapped already
net use | find "DavWWWRoot" >nul
if %errorlevel% neq 1 (
net use %letter% /d
exit /b
)
:top
for /f "tokens=1-5 skip=3" %%f in ('arp -a') do (
if "!range!"=="" set range=%%f
if "%%g"==%mac% set ip=%%f
)
for /f "tokens=1-4 delims=." %%a in ('echo %range%') do (set range=%%a.%%b.%%c)
if "!ip!"=="" (
echo Discovering network...
for /L %%N in (100,1,120) do start /b ping -n 1 -w 200 %range%.%%N >nul
timeout 1 >nul
set ip=empty
goto :top
) else (
if "%ip%"=="empty" exit /b
echo Mapping %ip% to drive K
:: Use basic digest authentication. Manage in Credential Manager
net use %letter% http://%ip%:%port% /savecred /persistent:no 2>nul
if errorlevel 1 (
echo Error mapping drive %letter%
title Error mapping drive %letter%
net use %letter% /d 2>nul
pause
goto :top
) else (
if exist %letter% explorer %letter%
exit /b
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment