Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy Android MTP files using linux terminal or python; error Operation not supported

i'm trying to create my own python script to backup Android images.i can see the Android mounted well, and i can move files back and forth using nautilus but not from CLI

the CLI error is "Operation not supported"

hkhrais@Hkhrais:/run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C006%5D/Phone/Download$ cp  DSC03951.JPG /home/hkhrais/Desktop/

cp: cannot open ‘DSC03951.JPG’ for reading: Operation not supported

python code

try:
            shutil.copyfile('/run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C006%5D/Phone/Download/DSC03951.JPG', "/home/hkhrais/Desktop/test")

except:
    raise


Traceback (most recent call last):
  File "scriptt.py", line 33, in <module>
    main()
  File "scriptt.py", line 18, in main
    shutil.copyfile(img, "/home/hkhrais/Desktop/test")
  File "/usr/lib/python2.7/shutil.py", line 82, in copyfile
    with open(src, 'rb') as fsrc:
IOError: [Errno 95] Operation not supported: '/run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C006%5D/Phone/Download/DSC03951.JPG'

Android 4.2.2 Python 2.7 Ubuntu 14.4

any idea or alternative way please ?

like image 389
client eastwood Avatar asked Aug 22 '14 22:08

client eastwood


Video Answer


2 Answers

Use gvfs-copy instead of cp. For example:

gvfs-copy "mtp://[usb:002,06]/Phone/Download/DSC03951.JPG" /home/hkhrais/Desktop/

For executing this command in python you can use os.system:

import os
os.system('gvfs-copy "mtp://[usb:002,06]/Phone/Download/DSC03951.JPG" /home/hkhrais/Desktop/')
like image 86
mhsekhavat Avatar answered Oct 17 '22 19:10

mhsekhavat


try using ptp (I got the same error when using MTP) but PTP worked. from settings you can change how android phone appears to your computer when the device is connects, android 5 hast two options, PTP and MTP.

like image 42
user8768313 Avatar answered Oct 17 '22 18:10

user8768313