Previous Section  < Day Day Up >  Next Section

Recipe 23.18. Connecting Linux Clients to Samba Workgroups with Command-Line Tools

23.18.1 Problem

Graphical LAN browsers, like the ones discussed in Recipe 23.17, are nice, but you really want a command-line tool for browsing Samba shares and transferring files. You don't always run an X session, or maybe you just prefer the console.

23.18.2 Solution

Use smbclient to list available shares and to transfer the files you want. With smbclient, you don't need to mount shares to get or upload the files; it's just like using File Transfer Protocol (FTP).

Another option is to use smbtree and smbmount/smbumount. smbtree is an ASCII-text LAN browser, so you don't need to run X to use it. Use smbtree to display the hosts and shares in your workgroup, then use smbmount/smbumount to mount and unmount the shares you want to use.

23.18.3 Discussion

To use smbclient, first give it the hostname of your Samba server to show a list of shares:

$ smbclient -N -L windbag

...

        Sharename       Type      Comment

        ---------       ----      -------

        share1          Disk      testfiles

        share2          Disk      more testfiles

        share3          Disk      testfiles galore

...

Then connect to the share you want:

$ smbclient -N //windbag/share1

Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.0.5-Debian]

smb: \>

To list the files, use ls:

smb: \> ls

.                           D        0  Sat Aug 14 16:47:24 2003

  ..                        D        0  Sat Aug 14 16:46:14 2003

  chatscripts               D        0  Sat Aug 14 16:47:24 2003

  calendar                  D        0  Sat Aug 14 16:47:05 2003

   

                47838 blocks of size 65536. 17571 blocks available

Files are transferred by using the familiar old FTP commands:

smb: \> cd chatscripts

smb: \chatscripts\> ls

.                            D        0  Sat Aug 14 16:47:24 2004

  ..                         D        0  Sat Aug 14 16:47:24 2004

  provider                   A      656  Tue Aug 19 15:14:46 2003

   

                47838 blocks of size 65536. 17571 blocks available

smb: \chatscripts\> get provider provider-copy

This command downloads the file provider to your local working directory and renames it provider-copy. To upload the provider-copy file when you're finished, without changing the name, use:

smb: \chatscripts\> put provider-copy

You can call up a list of commands with the question mark:

smb: \> ?

To terminate your session, use:

smb: \> quit

smbtree looks like this:

$ smbtree -N

WORKGROUP

   \\WINDBAG               anonymous lan file server

           \\WINDBAG\ADMIN$        IPC Service (anonymous lan file server)

           \\WINDBAG\IPC$          IPC Service (anonymous lan file server)

           \\WINDBAG\share2        shared filenthinngs

           \\WINDBAG\share1        testfiles

   \\STINKPAD              lil black box

           \\STINKPAD\ADMIN$       IPC Service (lil black box)

           \\STINKPAD\IPC$         IPC Service (lil black box)

   \\POWERPC               celeron

           \\POWERPC\IPC$          Remote Inter Process Communication

           \\POWERPC\PRINTER$

When you see the share you want, mount the share on your system with smbmount, using a directory created for this purpose, and mind your slashes:

$ mkdir samba

$ smbmount //powerpc/c-win98 samba -o guest

To unmount the share when you're finished, use:

$ smbumount  samba

-o guest prevents Samba from asking for a password. Use this on anonymous shares that don't need authentication. If a login is required, enter your username:

$ smbmount //windbag/andrew  samba -o andrew

added interface ip=192.168.1.5 bcast=192.168.1.255 nmask=255.255.255.0

Password:

smbmount must be SUID for ordinary users to be able to use it. If your installation did not do this already, set the SUID bit this way:

# chmod +s smbmount

23.18.4 See Also

  • smbmount(8), smbumount(8), smbtree(1)

    Previous Section  < Day Day Up >  Next Section