Network Transparency with KIO

by Jes Hall

Kioslaves are out-of-process protocol handling plugins that let you access various services as though they were part of your local filesystem. They can be accessed through the Konqueror file manager and any standard file dialog in most KDE applications. The applications using Kio don't need to be aware of how to access the remote host or device—the ioslave handles it all. This provides powerful and flexible network transparency for KDE applications.

KDE includes a large range of basic kioslaves. Some KDE add-on applications install their own. You can add new kioslaves at any time, and all KDE KIO-aware applications will work with them. If you use Konqueror as a Web browser, you're already using KIO, as the HTTP, HTTPS and FTP protocols are implemented as kioslaves.

Fish

The KDE fish kioslave provides a graphical interface for manipulating files over Secure SHell (SSH). Fish should work with any POSIX-compliant UNIX providing it has a Bourne-compatible shell as /bin/sh and basic file manipulation utilities like cat, chgrp, chmod, chown, cp, dd, env, expr, grep, ls, mkdir, mv, rm, rmdir, sed and wc. If Perl is available, it is used instead. In that case, only env and /bin/sh are needed out of the list above, and using Perl has the advantage of being much faster. I've used fish to log in to Linux, FreeBSD, Mac OS X and Solaris with equal success.

Most of what is discussed in this article holds true of the ftp and sftp kioslaves as well, which present much the same interface to the user.

Here, I'd like to use fish to log in to my Apple Macintosh computer to grab some files and copy them locally. Because it's running a variant of UNIX with env and Perl and has sshd running, fish will work with it just fine. To log in to a remote host, type:

fish://username@host

into the Konqueror address bar. If your remote sshd is listening on a custom port, you can specify this at the end of the URL:

fish://username@host:9999

If this is the first time you've tried to connect to this host over SSH, Konqueror brings up a dialog noting that it cannot verify the authenticity of the host and asks for your input to proceed. Select Yes to indicate that you want to continue connecting to this host. SSH then caches the fingerprint of this host in your ~/.ssh/known_hosts file.

Unless you have SSH keys set up for passwordless login, Konqueror shows a dialog asking you to enter your password. Ticking the box Keep password saves the password into your KWallet. This can be very convenient if you plan to access this host often.

Now I'm logged in and looking at my home directory on the remote host. I need to find the image I want out of the image files stored here. With the size of my digital photograph library, none of the images are named descriptively, and unfortunately, without being able to look at the images, I really have no idea which is the one I want.

One of the areas where fish really shines is the way it lets you preview remote files in much the same way you would preview local ones. KDE's preview mechanism is flexible and powerful, enabling you to see previews of images, PDF files, fonts and office documents as well as listen to previews of audio files.

To enable previews over fish, select Configure Konqueror... from the Konqueror Settings menu. Navigate to Previews & Meta-Data in the dialog that appears. Under Internet Protocols, tick the box next to fish. Adjust the slider beneath Maximum file size to a sane value for the speed of the connection you're using. If you're accessing hosts over the Internet, you probably don't want Konqueror to attempt to generate thumbnail images of 100MB TIFF files. Click OK and you're done.

To fine-tune exactly the specific file types for which you want to see previews, look under Preview in the View menu. Here you can enable various file types for showing previews, and also quickly toggle between enabling and disabling previews globally. If you had a Konqueror window open while adjusting these settings, you may need to click reload before you see any changes.

Now I can see previews of my images, and I've found the one I want. I can drag and drop it to an open Krita window for editing and save my changes afterward directly to the remote host. Or, I simply could copy the file locally for further processing, also using drag and drop.

Figure 1. KDE's ability to display previews over remote protocols makes finding the file you want a breeze.

Fish lends itself well to the simple maintenance of remote Web sites. Tasks like moving, renaming and changing permissions on remote files are easy when you approach them from Konqueror's familiar file management interface.

Changing permissions for files on a Web server is a common task. Often the default permissions on files created on your Linux box can be too restrictive and result in a Forbidden error message when people try to access the files over the Web. To change the permissions of a file over fish, right-click on the file and select Properties. On the Permissions tab choose Can read for both Group and Other permissions, and click OK. If you were changing permissions for a CGI, you also would tick the box labeled is executable.

In KDE 3.5, Kate gained the ability to save a working set of documents as a session to be resumed easily again later. When coupled with fish, this makes, for me at least, the ultimate Web development environment.

To open up all of the HTML, CSS and other files associated with my Web site in Kate, I can drag and drop them from an open Konqueror window showing me a fish session to the remote host. Dragging and dropping multiple files in this way causes them to be opened as separate files that I can navigate between in the Documents pane.

If you prefer to use a more GUI-oriented Web development tool rather than editing files manually in Kate, the full-featured integrated Web development environment, Quanta Plus, is also KIO-enabled.

You can use the File→Open dialog to take advantage of KIO network transparency. All standard KDE file dialogs have support for kioslaves. To load files over fish, select Open from the File menu. In the location bar at the top of the file dialog, type your fish URL:

fish://canllaith@canllaith.org

Navigate to where the files associated with your Web site or where other projects are kept, and open the files you want to be a part of the session. To open multiple files at once, hold down the Ctrl key and click once on each file you want to open. When you're finished selecting files, click Open.

If you plan to access this remote host often, you can add a shortcut to the icon bar on the left of the dialog. Choose the directory to which you want the shortcut to point, and drag it to the icon bar. You can edit the name, icon and other attributes of this shortcut by right-clicking on it and selecting Edit Entry.

Figure 2. The Kate Open File Dialog, Displaying a Remote Location over Fish

Once Kate has loaded the files you want to save as a session, select Save As from the Sessions menu. Enter a name for your new session—as I'm saving various files relating to my Web site, I call my session canllaith.org.

In the future, when you want to load this set of remote files quickly, you can choose the saved session from the Sessions menu. I use this tool time and time again. At the end of a day of working on a Web site and opening various remote files from all over the directory tree, I simply save them as a session with the date and a short descriptive name. Next time, remembering where I left off and what files I was working on is a little bit easier.

Samba

The smb kioslave included with KDE lets you browse Microsoft Windows smb file shares. It requires that you install libsmbclient. If you navigate to smb:/ in Konqueror (or use the nifty Alt-F2 shortcut described below), you will be shown any Windows workgroups found, and you can browse through them for the host you want. You also can specify a host or a specific share of a host directly with:

smb://username@hostname/share

Like fish, if you don't specify a user name, Konqueror prompts you for a user name and password pair that you can save with KWallet. If you always use a particular user name/password pair on your Samba network, rather than having to save passwords individually for every host you access, you can configure this to be supplied automatically by KDE. In the KDE Control Center, navigate to Internet & Network→Local Network Browsing. Here you can enter the default user name and password pair you want KDE to use for its Samba client.

As well as adding shortcuts to the File dialog, you also can add desktop shortcuts to hosts you want to access frequently. To create a desktop shortcut to an smb URL, right-click on the KDE desktop and select Create New→Link to Location (URL)... from the context menu. Fill in the smb:// (or fish) URL to the share to which you want to create the shortcut in the box labeled Enter link to location (URL):. KDE fills in the filename box with a suitable name, or you can choose your own. Click OK and you're done.

Figure 3. Creating a Desktop Shortcut for a Location Accessible over Samba

As well as accessing kioslaves through the Konqueror address bar and KDE standard file dialogs, you can load kioslaves quickly with the KDE Run Command box. Try pressing Alt-F2 to bring up the Run Command box, and type help:/kwrite. A Konqueror window is launched showing you the KWrite Handbook. This works with all kioslaves and is a handy way of looking up help pages or loading a remote URL quickly, if, like me, you tend to have a rather cluttered screen.

Many other interesting kioslaves are included with KDE, and you can download other third-party efforts from kde-apps.org as source code that can be compiled against a recent KDE version. To find them, search for “kio” on the KDE-apps.org search page. If you want to compile the kioslaves you've downloaded, you need to have a working C++ compiler and the appropriate development libraries for KDE and Qt installed. Usually these are packaged separately from the KDE runtime libraries.

To find out which kioslaves you have installed, type help:/kioslave in the Run Command box or the Konqueror address bar. This is the KDE help kioslave, which lets you access the help documentation for installed KDE programs through Konqueror. Some of the more interesting kioslaves include:

  • cgi: this kioslave executes CGI programs without needing to have a running Web server. It is really handy for off-line local testing of CGI scripts.

  • locate: Kubuntu includes kio-locate by default, and you can download the sources for other distributions from KDE-apps.org. kio-locate is a kioslave for locate or slocate. Typing locate: query term into any KIO-enabled field displays the results from the locate database. This is immensely convenient when combined with the File dialog. Want to open that budget spreadsheet in KSpread, but you realise you can't quite remember where you saved it until after you've launched the application? Without having to leave the File dialog, locate:/ comes to the rescue.

  • tar: this kioslave allows you to browse the contents of tar, tar.bz2 and tar.gz archives. It's registered as the default handler for these files within KDE. This lets every KDE application handle loading and saving files to archives transparently without needing to extract them. With previews enabled, it's easy to find the single file that you want out of the hundreds or even thousands in the archive.

  • zip: this kioslave lets you browse the contents of zip archives, much like the tar kioslave does for tar archives.

  • info/man: the info and man kioslaves provide a friendly interface to reading man and info pages. The info kioslave in particular makes navigating pages much easier with a mouse-driven browser interface that's more simple to use than the command-line tool.

  • audiocd: this kioslave provides a simple interface for ripping and encoding files from music CDs to Ogg, MP3 or flac using drag and drop.

Figure 4. The locate kioslave shows the results of the query “kio” in my home directory.

Konqueror is an application with amazing flexibility as both a Web browser and file manager, due mostly to its extensibility with kioslaves. The kioslaves featured above are barely the tip of the iceberg. Experiment with those listed in help:/kioslave to see what else Konqueror can do.

Jes Hall is a KDE developer from New Zealand who is passionate about helping open-source software bring life-changing information and tools to those who would otherwise not have them. She welcomes comments sent to jhall@kde.org.

Load Disqus comments