How I Transfer File Cross-platform

Too Young

In the old days, I can’t remember clearly, but I thought that I would use instant messengers to transfer files, just like many others. Ignorant naive, too young, too simple.

GNU/Linux Affair

Later on, I switch to GNU/Linux, and to be honest, I did not realize that there’s a problem to transfer files between different systems as I was using Debian with KDE Plasma and Android at the time. KDE Connect does it all for me.

Back to Windows

When I switched back to Windows at the emergence of Windows Subsystem for Linux (WSL), I’ve been using the built-in HTTP server of Python along with a PowerShell alias:

# Run it directly
python -m http.server
# Set alias in PowerShell profile
function pyd { python -m http.server }

It’s really slow, but still acceptable. The only problem is that it does not set the proper file encoding so when browsing a file containing non-ASCII characters directly, you will get garbled text.

Revisit KDE Connect

Windows

Earlier this year, I found out that Microsoft Store has KDE Connect, and happily switched back to it despite minor annoyance.

Then someday I was finally fed up and thus set up context menu for a quick transfer. In this case I would use ContextMenuManager, but you can archive the same with vanilla Windows settings.

First, create a Shell (not ShellEx) menu.

In the pop-up window, set the following:

  • Menu Text: Share via KDE Connect
  • Menu Command: kdeconnect-cli.exe
  • Command Parameter: --name {YOUR_PARIED_DEVICE} --share "%1"

Remember to change {YOUR_PARIED_DEVICE} to a real name like Switchroot.

Then, customize the icon by setting the path of kdeconnect-cli.exe. You can get the executable path via a PowerShell command:

Get-Command kdeconnect-cli.exe | Select-Object -ExpandProperty Source

For me it’s %LOCALAPPDATA%\Microsoft\WindowsApps\kdeconnect-cli.exe. Convert it to a real path before using.

Finally, pin the custom KDE Connect context menu to top.

You can now enjoy probably the fastest file transfer. Simply select a few files, right click when pressing Shift to open the full context menu, choose Share via KDE Connect and boop, transfer done.

Xfce

In this case, I use Thunar Custom Action and Send To Menu as example. As it’s basically the same as Windows, I’ll just leave plain config.

Custom Action (part of ~/.config/Thunar/uca.xml):

<action>
	<icon>kdeconnect</icon>
	<name>Share via KDE Connect</name>
	<submenu></submenu>
	<unique-id>blahblah</unique-id>
	<command>kdeconnect-cli --name {YOUR_PARIED_DEVICE} --share %F</command>
	<description>Send files in batch</description>
	<range>*</range>
	<patterns>*</patterns>
	<audio-files/>
	<image-files/>
	<other-files/>
	<text-files/>
	<video-files/>
</action>

Send To:

# NOT $XDG_DATA_DIRS!
mkdir -p $XDG_DATA_HOME/Thunar/sendto/
# NOT $XDG_DATA_DIRS!
cd $XDG_DATA_HOME/Thunar/sendto/

cp /usr/share/Thunar/sendto/kdeconnect-thunar.desktop ./kdeconnect-thunar.desktop
vim kdeconnect-thunar.desktop
-Exec=kdeconnect-handler %F
+Exec=kdeconnect-cli --name {YOUR_PARIED_DEVICE} --share %F

Of course it’s also applicable to other DE or even WM, you only need to rewrite it in the native way of your favorite DE/WM/file manager. For example, Dolphin service menus on KDE Plasma (or wherever as long as you use Dolphin + KDE Connect). Actually it’s also possible to assign a hotkey to trigger a script, which would then send files in a terminal file manager like nnn.

Potential Improvement

It can be improved in several ways:

  • You can only transfer files, not folders due to the limitation of kdeconnect-cli. This can surely be bypassed by writing a wrapper and archiving folders on-the-fly, but it’s not worth the effort IMO
  • You need to press Shift every time as Windows 11 only shows a few useless context menu by default since who knows whenever
  • I assume you only have one specific device to transfer by setting the device name in command parameter. You can still transfer to other devices via the traditional KDE Connect way. Or in a not so elegant way, create multiple shell menus for each device…

Revelation

With RomVault, Retool, fixDat & Digital Preservation#Rsync leveraging rsync, I’ve pretty much settled on that due to the enormous possibility. Despite not built for Windows, rsync can be run inside WSL. If you compile WSL2-Linux-Kernel with my patch containing USB support, it’s even possible to act as a backup solution with correct file structure and permission with native transfer compression (and more importantly, delta transfer sadly this does not work for local transfer and although overwriting via undocumented params works, it’s still unsatisfying and thus not recommended).

What’s more, with the powerful include/exclude list, it almost replaces (my legitimate copy of) Beyond Compare and file indexer like Everything or fzf/ncdu2 in my case, not to mention how easy it is to recover dotfiles on a new machine even w/o git or Internet access.

Postscript

Of course, with Termux on Android, WSL on Windows and probable term emulator on iThings™, there are many more (reliable) ways to transfer (many) files as they are technically all GNU/Linux or at least Busybox, just to name a few (listed randomly, NOT ranked):

  1. scp (worst choice)
  2. ftp (just works™)
  3. rsync via ssh (-e ssh, blazingly fast)
  4. sshfs (mount locally)
  5. remmina (visualization)
  6. bcompare (side by side comparison)

Reference

Vinfall's Geekademy

Sine īrā et studiō