MTP (简体中文)
MTP 是 "Media Transfer Protocol" (媒体传输协议)的缩写,一些媒体播放器(例如 Creative Zen)和手机(例如 Android 3+ 的设备)会使用此协议.此协议也是 "Windows Media" 框架的一部分,且和 Windows Media Player 有异常紧密的联系.
Contents
安装
libmtp 提供了 Linux 下的 MTP 支持,可以从 official repositories 直接安装 libmtp.
kio-mtp 提供了 KDE 桌面环境的 MTP 整合.
用法
一旦安装后,就拥有很多的 MTP 工具. 想要尝试连接到 MTP 设备,使用以下的指令:
# mtp-detect
来查看 MTP 设备是否检测到.
使用以下指令连接到设备:
# mtp-connect
如果连接成功,您将会利用 mtp-connect
拥有几个切换选项用于访问您设备上的数据.
同样,你也可以使用以下的独立命令来访问您的 MTP 设备:
mtp-albumart mtp-emptyfolders mtp-getplaylist mtp-reset mtp-trexist mtp-albums mtp-files mtp-hotplug mtp-sendfile mtp-connect mtp-folders mtp-newfolder mtp-sendtr mtp-delfile mtp-format mtp-newplaylist mtp-thumb mtp-detect mtp-getfile mtp-playlists mtp-tracks
如果您看到类似以下的信息:
Device 0 (VID=XXXX and PID=XXXX) is UNKNOWN. Please report this VID/PID and the device model to the libmtp development team
则需要检查您的设备是否存在于以下的列表中:[Supported devices list[1]]. 如果答案是否定的,请报告给开发团队.如果已经存在了,也许是因为 libmtp 稍微的有点过时.为了可以正常的使用 libmtp, 您应该将自己的设备信息添加到以下文件中:
/usr/lib/udev/rules.d/69-libmtp.rules
使用媒体播放器
您也可以在音乐播放器中使用 MTP 设备,例如 Amarok 等. 但是您也许要做以下的操作:编辑 /etc/udev/rules.d/51-android.rules
[ MTP 设备使用示例如下(以 Galaxy Nexus 为例)]:
执行命令:
$ lsusb
查看您的设备信息,他们一般看起来像:
Bus 003 Device 011: ID 04e8:6860 Samsung Electronics Co., Ltd GT-I9100 Phone [Galaxy S II], GT-P7500 [Galaxy Tab 10.1]
在这种情况下,条目将是:
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0666", OWNER="[username]"
然后重新载入 udev 规则:
# udevadm control --reload
mtpfs
Mtpfs 是基于 FUSE 的文件系统,其支持读写 MTP 设备. 本质上是将您的设备挂载为扩展设备.
Mtpfs 可以从软件包 mtpfs 中获得,它在 Official Repositories (简体中文) 中.
- 首先,编辑
/etc/fuse.conf
注释掉以下行:
user_allow_other
- 使用以下命令挂载设备:
$ mtpfs -o allow_other /media/挂载点
- 使用以下命令卸载设备:
$ fusermount -u /media/挂载点
- 以 root 命令卸载设备:
# umount /media/挂载点
当然,你也可以将其写入 ~/.bashrc 中:
alias android-connect="mtpfs -o allow_other /media/YOURMOUNTPOINT" alias android-disconnect="fusermount -u /media/YOURMOUNTPOINT"
或者使用 sudo:
alias android-disconnect="sudo umount -u /media/YOURMOUNTPOINT".
jmtpfs
jmtpfs 是基于 FUSE 和 libmtp 用来访问 MTP (Media Transfer Protocol) 设备的文件系统.它专门为那些需要在 Linux 系统和新的 Android 系统之间交互文件,但是并不拥有 USB Mass Storage (只能使用 MTP) 的设备设计的. jmtpfs 可以从 AUR 的 jmtpfs 中获取.
使用此命令挂载设备(需要确保挂载点可用):
$ jmtpfs ~/mtp
使用此命令卸载设备
$ fusermount -u ~/mtp
go-mtpfs
If the above instructions don't show any positive results one should try go-mtpfs-git from the AUR. The following has been tested on a Samsung Galaxy Nexus GSM, Asus/Google Nexus 7 (2012 1st gen model) and Samsung Galaxy S 3 mini. (This is the only mtp software which worked for me on nexus 4. Settings are usb debugging enabled, connected as media device.)
If you want do it simpler, install go, libmtp and git from the official repositories. After that install go-mtpfs-git from the AUR.
As in the section above install android-udev which will provide you with "/usr/lib/udev/rules.d/51-android.rules" edit it to apply to
your vendorID and productID, which you can see after running mtp-detect. To the end of the line add with a comma OWNER="yourusername". Save the file.
- 将用户添加到 "fuse" 组:
gpasswd -a [user] fuse
- 如果该组不存在,请用以下的命令创建:
groupadd fuse
注销用户或者重启计算机以使得更改生效.
- 建立名为 "Android" 的挂载点:
mkdir Android
- 挂载设备:
go-mtpfs Android
- 卸载设备:
fusermount -u Android
您可以在 .bashrc 为这个命令设置一个别名,来让它更加的符合你的口味.
gvfs-mtp(译者推荐)
Philip Langdale 提供了 gvfs 下的 MTP 本地实现. gphoto2 和 mtpfs 缺陷在此页面查看:blog post.
- gvfs 下的 MTP 本地实现已经和 gvfs 上游合并,且在 gvfs 1.15.2 中正式发布.
- 您可以从 extra 中安装 gvfs-mtp,安装后需要重启计算机来让更改生效.
- 设备的 gvfs 路径就像是下面展示的这样(请注意,在连接设备的时候需要保证设备没有锁屏):
gvfs-ls mtp://[usb:002,013]/
simple-mtpfs
This is another FUSE filesystem for MTP devices. You may find this to be more reliable than mtpfs. simple-mtpfs is available in the AUR or can be built from source. Remember do not run the following commands as root.
- To list MTP devices run
simple-mtpfs --list-devices
- To mount a MTP devices (in this example device 0) run
simple-mtpfs /path/to/your/mount/point
- To un mount run
fusermount -u /path/to/your/mount/point
KDE MTP KIO Slave
这是一个基于 libmtp 实现的 MTP KIO Slave 方案,可以从此软件包安装: kio-mtp .
Using KIO makes file access in KDE seamless, in principle any KDE application would be able read/write files on the device.
用法
您可以在路径 mtp:/ 下访问设备.
KDE 设备的行为不能工作的解决方案
如果您不能使用"在文件管理器中打开"的动作,也许是遭遇到一个文件,编辑 /usr/share/apps/solid/actions/solid_mtp.desktop
将
Exec=kioclient exec mtp:udi=%i/
更改为
Exec=dolphin "mtp:/"
GNOME gMTP
gMTP 是原生的 Gnome 程序, 使用它可以方便的管理 MTP 设备.
Android 的解决方案
- HTC Phones automatically enter usb debugging mode on usb connect. Manually turn it off once connected to give libmtp access to the device.
MTP is still buggy and may crash despite the best efforts of developers. The following are alternatives:
- AirDroid - 一个 Android 应用,通过网络浏览器访问您的文件.
- Android 上的 FTP 客户端 - If you run a local FTP server on Arch (such as Vsftp), there are many FTP clients available on the Play Store which will give read/ write access to your device's files.
- FTP Server on Android. Note: since FTP client using passive transfer (server connect to client) do not forget to disable firewall or adding rules for allowing FTP server connect to your PC.
- Ftp Server (by The Olive Tree) app in Play Store acts as FTP server on Android and allows RW access to pretty much all your storage.
- Pro: Doesn't require root and just works!
- Cons: Doesn't work with tethering network.
- FTPServer (by Andreas Liebig) - Just work.
- Ftp Server (by The Olive Tree) app in Play Store acts as FTP server on Android and allows RW access to pretty much all your storage.
- SSH server on Android.
- For example, SSHelper, available on the Play Store, just works without requiring root access. Assuming SSHelper is listening on port 20 and the phone's IP address is 192.168.0.20, the following command will synchronise a local directory with the external SD card of the Android device:
rsync --rsh="ssh -p 20" --modify-window=1 ~/local_files 192.168.0.20:/mnt/extSdCard/remote_files
Note the --modify-window
option, which is often used when rsyncing to a FAT filesystem (such as the one used by Android devices for their internal memory and external SD cards).
- Samba - an Android app to share your SD card as a windows fileshare. Pros: Your desktop apps work as before (since the SD card appears as a windows fileshare). Cons: you need to root your phone.
- adb - Part of the Android development kit is adb android debug bridge. It can be used to push and pull files from an Android device.
- The device need USB debbuging to be active and later connected to the computer with usb.
- To send a file to the device use
adb push /what-to-copy /where-to-place-it
- To receive a file
adb pull /what-you-want-to-copy /where-you-want-it
- Pro: Stable, can be used for a lot more then just copy files back and forth.
- Cons: Can be somewhat slow.
Android 安全特性
如果您的设备使用的是 Android 4.x 以上的系统,请在解锁设备(锁屏)后再与 USB 连接.
如果您没有解锁设备,在 KDE 下您会收到 "No Storages found. Maybe you need to unlock your device?" 的提示,终端环境下,则会显示 02fe.