Connect to your android phone and copy files under Linux

13 September 2018 HackssysadminTechnology

OK, so MTP is a protocol, that’s implemented in Linux just as good as my Tennis skills. I’ve never played tennis. So usually it’s a tedious job to find some MTP build that will actually let you connect to your phone, usually by manually mounting it with some rag-tag tool.
The bellow method is a bit risky, since you need to set your phone to developer mode and unlock USB debugging.

So the solution I’ve been told by a colleague of mine is to use adb. It’s Android developer’s tool. First you need to set your phone to developer mode – google it if you don’t know how (too lazy to write it atm), then enable USB debugging (you know where to see how) and after that install adb. I assume you use Debian based OS (the others should be competent enough to know how to implement my guide) so first you need to install adb
[code]sudo apt-get install adb -y[/code]
Then – you need to connect to your device to check your mountpoint:

$ adb shell
zeroflte:/ $
zeroflte:/ $ ls
acct init.usb.rc
bugreports init.wifi.rc
cache init.zygote32.rc
config init.zygote64_32.rc
d knox_data
data lib
default.prop mnt
dev oem
efs persdata
etc postrecovery.do
factory preload
file_contexts.bin proc
fstab.goldfish property_contexts
fstab.ranchu publiccert.pem
fstab.samsungexynos7420 root
fstab.samsungexynos7420.fwup sbfs
init sbin
init.baseband.rc sdcard
init.carrier.rc seapp_contexts
init.container.rc sepolicy
init.environ.rc sepolicy_version
init.goldfish.rc service_contexts
init.gps.rc storage
init.ranchu.rc sys
init.rc system
init.rilchip.rc ueventd.goldfish.rc
init.rilepdg.rc ueventd.ranchu.rc
init.rilmptcp.rc ueventd.rc
init.samsungexynos7420.rc ueventd.samsungexynos7420.rc
init.samsungexynos7420.usb.rc vendor
init.usb.configfs.rc

The point of this step is to find the mountpoint of your storage. In my case (Samsung Galaxy S6) it’s sdcard

zeroflte:/ $ cd /sdcard/DCIM/Camera/
zeroflte:/sdcard/DCIM/Camera $ ls
20180106_130309.jpg 20180425_131007.jpg 20180601_152948_001.jpg
20180122_191023.jpg 20180503_113706.jpg 20180604_080840.jpg
20180126_214032.jpg 20180511_134625.jpg 20180605_074430.jpg
20180128_104540.jpg 20180511_134633.jpg 20180605_074454.jpg
20180128_104603.jpg 20180511_134650.jpg 20180606_204538.jpg
20180128_105016.jpg 20180511_134656.jpg 20180606_204602.jpg
20180128_105018.jpg 20180518_100415.jpg 20180606_204615.jpg
20180128_105032.jpg 20180518_111932.jpg 20180606_204712.jpg
20180128_105038.jpg 20180518_111938_001.jpg 20180606_211844.jpg
20180128_110116.jpg 20180518_111944.jpg 20180608_090222.jpg
20180128_110117.jpg 20180518_111951.jpg 20180622_170653.jpg
20180128_110119.jpg 20180518_111954.jpg 20180624_155424.jpg
20180128_110120.jpg 20180518_111957.jpg 20180624_155453.jpg
20180128_115832.jpg 20180518_112005.jpg 20180624_155520.jpg
20180128_115834.jpg 20180518_112019.jpg 20180630_121444.jpg
20180128_131820.jpg 20180518_112026.jpg 20180630_133613.jpg
20180128_143636.jpg 20180518_112256.jpg 20180630_175606.jpg
20180128_143652.jpg 20180518_112257.jpg 20180712_092516.jpg
20180128_143656.jpg 20180518_112300.jpg 20180722_165017.jpg
20180128_143934.jpg 20180518_112301.jpg 20180723_112438.jpg
20180131_113451.jpg 20180520_144014.jpg 20180730_192024.jpg
20180227_144745.jpg 20180524_181523.jpg 20180730_205123.jpg
20180227_145230.jpg 20180524_181651.jpg 20180805_112123.jpg
20180227_145237.jpg 20180525_181335.mp4 20180807_004003.jpg
20180227_145903.jpg 20180527_082408.jpg 20180807_004005.jpg
20180227_145908.jpg 20180527_082413.jpg 20180807_004007.jpg
20180227_151013.jpg 20180529_082256.jpg 20180824_123432.jpg
20180304_134328.jpg 20180530_200849.jpg 20180824_123448.jpg
20180304_134330.jpg 20180530_200907.jpg 20180824_123449.jpg
20180317_122159.jpg 20180530_200912.jpg 20180824_123452.jpg
20180331_223919.mp4 20180530_201006.jpg 20180824_123454.jpg
20180401_153621.jpg 20180531_122250.jpg 20180824_123457.jpg
20180401_153846.jpg 20180531_171543.jpg 20180824_123522.jpg
20180409_124244.mp4 20180531_192110.jpg 20180824_123524.jpg
20180413_151130.jpg 20180531_214356.jpg 20180904_094740.jpg
20180421_154957.jpg 20180531_214855.jpg 20180904_145406.jpg
20180421_155001.jpg 20180531_215505.jpg 20180908_204216.jpg
20180421_155015.jpg 20180531_220815.jpg 20180911_091248.jpg
20180421_155042.jpg 20180531_221211.jpg 20180911_143219.jpg
20180425_130229_001.jpg 20180601_152937.jpg

And voila – I can see my pictures. Exit the shell (ctrl+d works). And then copy the files you need. Keep in mind that ‘adb’ does not work with regular expressions, so you can’t copy something like 20180912*.jpg – it fails. If there’s a way – do let me know, please!

$ adb pull /sdcard/DCIM/Camera/20180824_123454.jpg .
6057 KB/s (4120194 bytes in 0.664s)