How can large amounts of files be transferred to Linux via MTP?


Question

I'm trying to copy all of my pictures from my Samsung Galaxy S9+ to my laptop (running Linux Mint). I can transfer a few files at a time no problem, but I have amassed 1000's of files in my pictures folder.



When attempting to copy the folder across using the file manager, the operation stalls and then fails every time. I would prefer to do it via the terminal, but since Samsung phones use mtp to transfer files, I have no idea what commands to use.


Answer

MTP is crap for that task – OK for a few files in "small folders", but stalling for folders with many files in, or copying many files, or trying things in parallel.



As you use Linux, ADB would be a great alternative. I use that with adbfs-rootless, which allows mounting the device locally on your computer and works like a charm (I'm using it for years, so I can confirm it works at least up to Oreo).



First, to get ADB running, you can check with How do I get my device detected by ADB on Linux?. ADB binaries are shipped in the repositories of many distributions by a name like android-tools-adb so you can easily install them; alternatively take a look at Is there a minimal installation of ADB? for an even smaller footprint.



Installation of adbfs is quite straight-forward if you have the essential build tools already installed on your system: according to the readme, next to build-essential you'll need libfuse-dev and pkg-config available on your system. The git package is only needed if you want to clone the Github repository (alternatively, you can simply download the code as ZIP). cd to the directory you've cloned/unpacked the code to, and run make. When that's done, copy the adbfs binary to your path (e.g. into /usr/local/bin or ~/bin if you've set that up), so you don't need to specify the full path with each call – and you are ready to use it.



Finally, create a mount-point (an empty directory where your device's file system shall appear, say mnt in your home directory), and mount it with adbfs ~/mnt – et voila, your copy party can begin; from the terminal or graphically is up to you. When done, use fusermount -u ~/mnt to unmount your device again.



As a little bonus for you: should you sometimes have multiple devices attached at the same time, you'll need to set the ANDROID_SERIAL environment variable to tell adbfs which device to connect to. Here's a little script making that easier for you:







  case "$(adb devices|grep -v "devices"|grep -v -e '^[[:space:]]*$'|wc -l)" in
0) echo "Nothing to mount (no device attached)" ;;
1) export ANDROID_SERIAL=$(adb devices|grep -v "devices"|grep -v -e '^[[:space:]]*$'|awk '{ print $1' } )
adbfs /mnt/droid
;;
*) devices=''
tmpfile=$(tempfile)
adb devices -l|grep -v "devices"|grep -v -e '^[[:space:]]*$' > $tmpfile
while IFS='\n' read i
do
test="$(echo $i | awk '{ print $2 } ')"
if [ "$test" = "device" ]; then
devices="$devices $(echo $i | awk '{ print $1 } ')"
devices="$devices \"$(echo $i | awk '{ print $5 } ')\""
fi
done < "$tmpfile"
rm -f -- "$tmpfile"
serial=$(whiptail --clear --menu 'Multiple devices found, make your choice:' 0 0 0 $devices 3>&1 1>&2 2>&3)
export ANDROID_SERIAL=$serial
adbfs /mnt/droid
esac


If you wonder about the indention: it's a snippet out of my Midnight-Commander (mc) menu. You can insert it there, preceding it by



= t d
+f ^mnt$
m Mount Droid


So whenever your mount point is highlighted by the cursor, pressing F2 will make that menu item available and you can easily mount your device. For unmounting, here's the second menu item:



+f ^mnt$
u uMount Droid
fusermount -u /mnt/droid


^mnt$ is the name of the mount-point you've created – so if you used a different name, you need to adjust this as well.



Enjoy!


Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes