2

I try to have as few programs installed as possibly. But I can't seem to find a reliable way to copy/move files from my PC to my Android smartphone. I use Debian and LineageOS on both of my Xiaomi devices.

Every time I use cp, mv or even rsync I get errors saying something like "input output error" or something like that.

I have used jmtpfs and android-file-transfer and I had problem with both of them.

Am I missing something, some drivers or something like that?

In the past I remember that when I used a file manager I didn't experience non of these problems but honestly I don't want to install a file manager just to be able to transfer files correctly from my PC to my phone.

I've read that using MTP is mostly a hit or miss. But how can the file managers be able to transfer files correctly?

1
  • 1
    Activate Debugger Options on your phone and in it ADB. For adb there are tools like adb-sync available.
    – Robert
    Commented Jan 21 at 8:45

2 Answers 2

1

The fastest way to transfer files from Android to a PC is always via adb [Android Debug Bridge]

Prerequisites


  1. Install Platform Tools:

    1. Debian:
      • Package Manager:
        sudo apt update; sudo apt install adb
        
      • Downloaded .zip:
        # Create and enter working directory:
          mkdir android; cd android
        
        # Download Platform Tools and unzip:
          wget -c https://dl.google.com/android/repository/platform-tools-latest-linux.zip
          unzip platform-tools-latest-linux.zip
        
        # Enter directory:
          cd platform-tools
        
        # Verify:
          ./adb version
        
        # To make permanent, edit user's shell .*rc file
          export PATH=/path/to/platform-tools:$PATH
        


    1. Windows:
      1. Download and extract platform-tools directory to %ProgramData%
      2. Open PowerShell / Cmd terminal: WinKey+ROpen: powershell || cmd → OK
        1. Add platform-tools to $env:PATH / %PATH%:
          # Once executed, close and reopen terminal:
            Cmd /c Setx /M Path "%PATH%;C:\ProgramData\platform-tools;"
          


  1. To use adb, enable USB Debugging on the device via Developer options:
    1. SettingsSearch Settings: buildBuild number
    2. Tap Build Number 7x until You are now a developer! shows
    3. SettingsSearch Settings: debuggingUSB Debugging → Toggle on

  2. Verify device is authorized to utilize adb:
    1. adb devices
      
    2. Approve USB debugging access request on device


4.1 Copy Directories

  1. Phone → PC:

    # Linux:
      # To current directory:
        adb pull -a -p "/sdcard/Path/to/Folder" .
    
      # To specific directory:
        adb pull -a -p "/sdcard/Path/to/Folder" "/path/to/folder"
    
    
    # Windows:
      # To current directory:
        adb pull -a -p "/sdcard/Path/to/Folder" .
    
      # To specific directory:
        adb pull -a -p "/sdcard/Path/to/Folder" "D:\Path\to\Folder"
    

  2. PC → Phone:

    # Linux:
      # From current directory:
        adb push -a -p "../<current folder>" "/sdcard/path/to/folder"
    
      # From specific directory:
        adb push -a -p "/path/to/folder" "/sdcard/path/to/folder" 
    
    
    # Windows:
      # To current directory:
        adb push -a -p "..\<current folder>" "/sdcard/Path/to/Folder"
    
      # From specific directory:
        adb push -a -p "D:\Path\to\Folder" "/sdcard/Path/to/Folder" 
    


4.2 Copy Files

  1. Phone → PC:
    # Linux: 
      # To current directory:
        adb pull -a -p "/sdcard/path/to/file" .
    
      # To specific directory:
        adb pull -a -p "/sdcard/path/to/file" "/path/to/folder"
    
    
    # Windows:
      # To current directory:
        adb pull -a -p "/sdcard/Path/to/File" .
    
      # To specific directory:
        adb pull -a -p "/sdcard/Path/to/File" "D:\Path\to\Folder"
    

  2. PC → Phone:
    # Linux:
      # From current directory:
        adb push -a -p "./<file>" "/sdcard/Path/to/Folder"
    
      # From specific directory:
        adb push -a -p "/path/to/file" "/sdcard/path/to/folder"
    
    
    # Windows:
      # From current directory:
        adb push -a -p ".\<file>" "/sdcard/Path/to/Folder"
    
      # From specific directory:
        adb push -a -p "D:\Path\to\File" "/sdcard/Path/to/Folder"
    


4.3 Copy Wildcard Extensions

  1. Phone → PC:
    • PowerShell:
      # Replace .ext with extension:
        adb shell ls "/sdcard/file/path/*.ext" | foreach {adb pull -a -p "$_"}
      
    • Cmd:
      (Must be executed from within directory files will be saved to)
      # Replace .ext with extension:
        for /F "delims=" %I in ('adb shell find "/sdcard/file/path/*.ext"') do (adb pull -a -p "%I")
      

  2. PC → Phone:
    • PowerShell:
      # Replace .ext with extension:
        ls ".\*.ext" | foreach {adb push -a -p "$_" "/sdcard/Path/to/Folder"}
      
    • Cmd:
      # Replace .ext with extension:
        for /F "delims=" %I in ('dir ".\*.ext" /B /O:-D') do (adb push -a -p ".\%I" "/sdcard/Path/to/Folder/")
      


Cleanup

  1. Disable USB Debugging → Disconnect Phone
    ADB can often be added to Quick Tiles for easy enabling/disabling of USB Debugging, as leaving it enabled when not in use is a data security issue (never enable wireless ADB, as it's not secure):
    Screenshot


adb <pull | push>

# ADB File Transfer:

  # Copy files/directories from device:
    adb pull [-a] [-z ALGORITHM] [-Z] REMOTE... LOCAL
      -a: preserve file timestamp and mode
      -p: display transfer progress
      -z: enable compression with a specified algorithm (any/none/brotli/lz4/zstd)
      -Z: disable compression

  # Copy local files/directories to device:
    adb push [--sync] [-z ALGORITHM] [-Z] LOCAL... REMOTE
      -a: preserve file timestamp and mode
      -n: dry run: push files to device without storing to the filesystem
      -p: display transfer progress
      -z: enable compression with a specified algorithm (any/none/brotli/lz4/zstd)
      -Z: disable compression
      --sync: only push files that are newer on the host than the device


Reference Sources

2

MTP works usually fine for smaller file collections and if the files are not too large in GB sizes. According to Internet research, (keywords MTP maximum file size) MTP caps at 4GB of files. What I have seen to work reliably is adb push/pull, but it isn't very easy to handle as you need to know the exact path you're trying to cp from/to. Example:

adb pull /storage/9C33-6BBD/Adownload/widget_2_2023-04-01.json

or

adb push widget_2_2023-04-01.json /sdcard/

Alternatively you could use other ways of file transfer like one of the many cloud storages, host your own, or use file managers that employ file transfer protocols like FTP to communicate to some FTP server. Yet another way I found convenient in the past is to use an FTP server on Android (external link to F-DROID) and just copy the files with an FTP client like FileZilla.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .