Accessing Shares with smbclient

Accessing Shares with smbclient

Although we've already used it in a noninteractive mode, smbclient is really an interactive program that looks and acts like an FTP client. Simply invoke the utility with the name of the share. Remember that the share name can be specified with forward slashes if desired, and you may specify the username and workgroup also. A sample session would proceed as follows :

$ smbclient //homer/site-local
added interface ip=192.168.0.1 bcast=192.168.0.255 nmask=255.255.255.0
Password:
Domain=[CURTIS] OS=[Unix] Server=[Samba 2.0.7]
smb: \> dir
 . D 0 Tue Oct 24 18:58:00 2000
 .. D 0 Tue Oct 24 19:09:45 2000
 archive D 0 Tue Oct 24 18:58:21 2000
 perl-lib D 0 Sat Aug 14 15:43:24 1999
 www D 0 Mon Jul 31 18:00:18 2000
 sql D 0 Tue Oct 24 18:58:18 2000
44717 blocks of size 131072. 14061 blocks available
 smb: \> cd sql
 smb: \sql\> dir
 . D 0 Tue Oct 24 18:58:18 2000
 .. D 0 Tue Oct 24 18:58:00 2000
 tables.sql 3042 Sun Aug 20 22:47:05 2000
 data.sql 95706 Sun Aug 20 22:14:00 2000
44717 blocks of size 131072. 14061 blocks available
 
 smb: \sql\> lcd /tmp
 the local directory is now /tmp
 smb: \sql\> get tables.sql
 getting file tables.sql of size 3042 as tables.sql (86.8301 kb/s) (average 86.8304 kb/s)
 smb: \sql\> exit

The program prompts for a password (unless the -N option is used), and that information is used to authenticate to the share. All of same commands are available as in a typical FTP client: dir, ls, cd, lcd, get, put, prompt, mget, and mput, to name a few. The only difference is the exit command, which replaces bye.

Another difference from FTP is that all file transfers are performed in binary mode; that is, no translations between CR and CRLF are performed. Consequently, there is no equivalent to the FTP type command. If you are retrieving text files from a Windows share, you may want to use dos2unix or Perl -pe 's/\ r\ n$/\ n/' to perform the end-of-line translations.

 



Multitool Linux. Practical Uses for Open Source Software
Multitool Linux: Practical Uses for Open Source Software
ISBN: 0201734206
EAN: 2147483647
Year: 2002
Pages: 257

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net