Thursday, August 30, 2007

Mounting a Windows Shared Folder

Over the past year or so I've used several methods to transfer file between my wife's laptop (running Win XP Home) and my Debian box. I have several requirements of any such method:
  1. my wife's laptop is not always connected
  2. two way file transfers
  3. non-English characters in file names
  4. no crashes or stalls, no transfer errors
  5. usable in a script
  6. bulk file transfers
  7. large files
  8. one-time or automatic setup
While these seem rather obvious, it took quite a while before I converged on the right approach.

The first step is to share a folder on the Windows PC.

The next step is connect to that shared folder from the Linux PC:

I started out using the "Places->Connect to Server..." menu item on the Gnome panel. It's really easy: select "Windows share" in the Service type drop menu, and type in the relevant connection information (server, share, folder, etc.). This worked rather well as long as I was using nautilus for my file transfers. I couldn't figure out at the time how to access the remote files via a script with regular shell commands (e.g. cp, rm, mv).

I just recently learned that I was actually using Gnome VFS, and that files may be copied at the command line with the gnomevfs-copy utility, using the same file URI's that nautilus uses (they start with smb://).

Still, I wanted something that's not tied to Gnome, since I have plans to replace it with something else (I'll have more to say about that in the near future).

For a short while I used scp (secure copy) and sshfs (ssh user-space file system), but this method has several drawbacks: for starters I needed to setup an SSH server on my wife's laptop (available for free as part of Cygwin). It isn't straight forward.

There are other problems:
  • I can't access my wife's documents folder when I connect with my own username, even though it is shared
  • Filenames must be in English (I couldn't figure out how to configure this)
  • sshfs tends to stall in mid transfer on my setup, I didn't investigate why.
The next attempt was to mount the shared folders manually using smbfs (which is the method used at my workplace). I added the following line to /etc/fstab:

// /mnt/windows/C smbfs uid=<username>,gid=<username>,username=guest,guest,codepage=<codepage>,iocharset=utf8 0 0

  • my wife's machine has the local address
  • it has the whole C drive shared
  • I created the directory /mnt/windows/C to be used as the mount point
  • you should replace the text in red with your own stuff
  • the shared folder is treated here as if it is always available - I tried to add the noauto option but then the codepage and iocharset settings were ignored (probably due to a bug in smbmount).
Last week I got fed up with this and searched Google for smbfs - the first link I got pointed me to CIFS VFS -Advanced Common Internet File System for Linux. A few minutes later I tried the following line in /etc/fstab:

// /mnt/windows/C cifs noauto,noexec,nosuid,nodev,uid=<username>,gid=<username>,username=guest,guest,iocharset=utf8 0 0

And it worked just fine - it meets all of my requirements!

One last note: an issue that seems to be a FAQ is how to mount a folder like "My Documents" that's shared on the windows machine? - the problem is that the space messes up /etc/fstab. The solution is to use the octal code for the space character \040, as follows:

//\040Documents /mnt/windows/My\040Documents cifs noauto,noexec,nosuid,nodev,uid=<username>,gid=<username>,username=guest,guest,iocharset=utf8 0 0

Happy sharing!

1 comment: