randombio.com | Science Dies in Unblogginess | Believe All Science | I Am the Science
Thursday, January 6, 2022 | Computer troubleshooting

How to copy files from Android phone to Linux without going mad

It's 2022, but computer software is still giving us error messages that are unhelpful at best


B ack in the before-time, say ten years ago, it was easy to transfer photos from a cell phone to a PC: just attach the USB cable, mount the phone as an external hard drive, and copy them. After that stopped working, you could still transfer files over SMB with special FileManager apps. Or, if you didn't mind waiting twenty minutes for each file, you could use Bluetooth.

The SMB apps on my phone, an old Galaxy S6, suddenly stopped working one day for no apparent reason, my Bluetooth adapter somehow got . . . broken, yes, that's it, it got broken, and USB is following the dark path paved by the lumbering SCSI-osaurs: too big, too many pins, and too many incompatible connectors with different sizes and shapes.

The server logs say: Non-SMB packet of length 106. Terminating server. The phone pops up a message saying Can't connect. I suspect it might be an SMB protocol problem, but who knows? Whoever writes these error messages should have their underpants pulled up over their heads.

Sunrise

Red sunrise photographed on an S6 (top) vs a D7000 DSLR (bottom). A cell phone is preferable to a real camera in public because people think you're just some idiot taking selfies—they're only half right—but color rendition on the S6 is not so hot: red comes out orange and orange comes out yellow. (resized and cropped)

Example: a few years ago a colleague, in despair, asked me to help fix his non-working DNA microarray reader, a scientific instru­ment that probably cost $200,000. I took one look at it and said: Oh my God, are they using SCSI? And within 30 seconds, I had gotten it fixed by straightening out one of the flattened pins. God, how I hated SCSI, but the colleague thought I was a genius. Guess I sure fooled him.

How hard would it have been for the OS to pop up a little message saying

Excuse me, sir or madam, something is wrong with your SCSI setup. Would you mind terribly checking whether, perhaps, pin #36 is bent? There's a good fellow.

But no, it just said nothing, like an angry teenager. At best, it might say something like

An error occurred

This hasn't changed in thirty years.

So, here are three alternative ways of getting files off your phone.

1. Mail it to yourself

This is what most people seem to do: include the file as an attachment and email it to yourself. That way, google.com also gets to see it. This is so easy even my doctor can do it, but it's slow.

2. Transfer over USB using MTP

Android uses a protocol called Media Transfer Protocol (MTP), which is a new standard for transferring data over USB. Linux's mtp-tools (libmtp.sourceforge.net) have mtp-detect and a graphical version called gmtp. It's a work in progress: in the latest version, 1.1.19 (from Sept 2021, requires libusb and libusb-devel), mtp-detect still says Listing raw device(s): No raw devices found. The version in Debian seems to work better: it pops up a window with an inscrutable error message:

Unable to open a folder for SAMSUNG Android
Cache invalid, retry (internally handled).

After puzzling over this message for a few minutes, I realized that it means it wants you to try it again. To do that, jiggle the USB cable until the phone starts charging over the USB (USB charging is very unreliable on an S6 due to the flimsy connectors, which is why I always use a wireless charger.) Other phones may need to be unplugged and reattached.

It then pops up an empty window. This means you have to check on your cell phone for a message popping up asking you to give permission. If you tap OK on the phone, the window becomes populated and you get two panels. Click on the left panel where SAMSUNG (or whatever phone you have) is shown under Devices. Click on the Phone icon and you should see icons for DCIM, DCIM / Camera, Movies, etc. After a long pause, it will then show you a list of the files. Right-click on one of them, and a menu pops up. Select Copy. Then click on the left panel under My Computer (yes, these folks have no shame) to set the destination, right click again, and select paste. Et voilà, the file is copied.

If the cable isn't inserted right, it says

Unable to open a folder for SAMSUNG Android
No such interface "org.gtk.vfs.Mount" on object at path /org/gtk/vfs/mount/1

It's a lot of trouble and a lot of clicking, jiggling, and popping-up just to get a blurry image of a sunset. Luckily there's a better way.

3. Mobile SFTP

Mobile SFTP

Screenshot of Mobile SFTP transferred to computer using Mobile SFTP

Most Linuxers know about the outstanding Mobile SSH app, which allows you to log in to your server remotely from your phone and administer it using a command line. Mobile SFTP was written by the same programmer and uses a similar setup design, but apart from that it's completely graphical. Here's the procedure.

  1. Turn on sshd on your server and get your wireless network running. Turn on WiFi on the phone.

  2. Open the Mobile SFTP app, tap the three dots in upper right, and select SFTP settings.

  3. Enter your user name, the server name or IP, and the port. Mobile SSH is the same, except there is no space for a username. Unlike file manager apps, Mobile SFTP never stores your password on your phone, which is a highly undesirable thing to do.

  4. Tap OK. These steps only have to be done once.

  5. Open a connection by tapping on the three dots and selecting Connect.

  6. A password box should pop up. Type your server password.

  7. The screen splits in half. The upper half shows the remote directories, the lower half shows the local ones on the phone.

  8. Tap on the upper one to navigate to the destination directory.

  9. Tap on the lower one and long-tap the file to select it. A menu comes up. Select 'push'. It asks for confirmation, then the file is sent over sftp to whatever directory is selected in the upper screen.

Unlike normal sftp, there are no command lines to type, which means no paths to keep in your head, and it's probably the fastest way to transfer files from your cell phone. It's also far more secure. Another advantage is that with SFTP, unlike with SMB, you can upload your files from anywhere on the Internet, not just from the local LAN.

The biggest advantage, though, is thanks to OpenSSH, we've already seen every possible error message an SSH client can produce. The most popular one is when it tries to panic you whenever you re-install it, but then admits it knows what the real problem is:

WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!

It is also possible that a host key has just been changed.

In earlier versions, it would even tell you what file to edit and which line of the file is bad. Corporate employers routinely use MITM attacks, if they allow SSH at all. And no doubt the government already has a copy of all your host keys. SSH doesn't warn you about those problems because it can't see them. End result: you only see a warning message when it's not real. But at least it's trying to be helpful. If only they were all like that.


jan 06 2022, 11:33 am. updated jan 07 2022. new photo added jan 23 2022


Related Articles

Getting Linux to talk on a corporate network

Setting up Netgear AX1800 WiFi 6 router (RAX20) as wireless access point


On the Internet, no one can tell whether you're a dolphin or a porpoise

Linux troubleshooting
science
book reviews
home