smbclient

   
smbclient

The smbclient program is the "Swiss army knife " of the Samba suite. Initially developed as a testing tool, it has become a command shell capable of acting as a general-purpose Unix client, with a command set very similar to that of ftp . It offers the following set of functions:

  • Interactive file transfer, similar to ftp

  • Interactive printing to shared SMB printers

  • Interactive tar format archiving

  • Sending messages on the SMB network

  • Batch mode tar format archiving

  • "What services do you have?" querying

  • Debugging

Command synopsis

 smbclient //   server   /   share     [ password] [options]   

It is possible to run smbclient noninteractively, for use in scripts, by specifying the -c option along with a list of commands to execute. Otherwise, smbclient runs in interactive mode, prompting for commands such as this:

 smb:\> 

The backslash in the prompt is replaced by the current directory within the share as you change your working directory with smbclient 's cd command.

Options

-A authfile

Specifies a file from which to read the username and password used for the connection. The format of the file is as follows :

 username =   value   password =   value   domain   =   value   

This is to avoid having the password prompted for or have it appear in plain text in scripts. The permissions on the file should be very restrictive (0600, for example) to prevent access by unwanted users.

-b buffer_size

Sets the size of the buffer used when transferring files. It defaults to 65520 bytes and can be changed as a tuning measure. Generally it should be quite large or set to match the size of the buffer on the remote system. It can be set smaller to work around Windows bugs : some Windows 98 systems work best with a buffer size of 1200.

-B IP_addr

Sets the broadcast address.

-c command_string

Passes a command string to the smbclient command interpreter. The argument consists of a semicolon-separated list of commands to be executed.

-d debug_level

Sets the debug (logging) level, from 0 to 10, with A for all. Overrides the value in smb.conf . Debug level 0 logs only the most important messages; level 1 is normal; debug levels 3 and above are for debugging and slow smbclient considerably.

-D init_dir

Upon starting up, causes smbclient to change its working directory to init_dir on the remote host.

-E

Sends output from commands to stderr instead of stdout .

-h

Prints the command-line help information (usage) for smbclient .

-I IP_address

Sets the IP address of the server to which the client connects.

-i scope

Sets a NetBIOS scope identifier.

-l log_ file

Sends the log messages to log_file rather than to the log file specified in the Samba configuration file or the compiled-in default.

-L server

Lists services (shares) offered by the server. This can be used as a quick way to test an SMB server to see if it is working. If there is a name -service problem, use the -I option to specify the server.

-M NetBIOS_name

Allows you to send messages using the Windows messaging protocol. Once a connection is established, you can type your message, pressing Ctrl-D to end. The -U and -I options can be used to control the "From" and "To" parts of the message.

-N

Suppresses the password prompt. Useful when using share mode security and accessing a service that has no password.

-n NetBIOS_name

Allows you to override the NetBIOS name by which smbclient will advertise itself.

-O socket_options

Sets the TCP/IP socket options using the same parameters as the socket options configuration option. Often used for performance tuning and testing.

-p port_number

Sets the port number with which smbclient will connect.

-R resolve_order

Sets the resolve order of the name servers. This option is similar to the resolve order configuration option and can take any of the four parameters lmhosts , host , wins , and bcast , in any order. If more than one is specified, the argument is specified as a space-separated list. This option can be used to test name service by specifying only the name service to be tested .

-s filename

Specifies the location of the Samba configuration file. Used for debugging.

-t terminal_code

Sets the terminal code for Asian languages.

-T command_string tarfile

Runs the tar archiver, which is gtar compatible. The tar file that is written to or read from is specified by tarfile . The two main commands are c (create) and x (extract), which can be followed by any of these:

a

Resets the archive attribute on files after they have been saved. See also the g option.

b size

Sets the block size for writing the tar file, in 512-byte units.

g

Backs up only files that have their archive bit set. See also the a option.

I filename

Includes files and directories. This is the default, so specifying this is redundant. To perform pattern matching, see also the r option.

N filename

Backs up only those files newer than file .

q

Suppresses diagnostics.

r

Performs regular expression matching, which can be used along with the I or E option to include or exclude files.

X filename

Excludes files and directories.

-U username

Sets the username and, optionally , the password used for authentication when connecting to the share.

-W workgroup

Specifies the workgroup/domain in which smbclient will claim to be a member.

smbclient commands

help [smbclient_command]

With no command specified, prints a list of available commands. If a command is specified as an argument, a brief help message will be printed for it.

! [shell_command]

Shell escape. With no command specified, runs a Unix shell. If a command is specified, runs the command in a Unix shell.

altname filename

Causes smbclient to request from the server and then print the old-style, 8.3-format filename for the specified file.

cancel print_jobid [...]

Causes smbclient to request the server to cancel one or more print jobs, as specified by the numeric job IDs provided as arguments. See also the queue command, which prints job IDs.

chmod filename octal_mode

Requests that the server change the Unix file permissions on filename to octal_mode , specified in octal numeric format. Works only if the server supports Unix CIFS extensions.

chown filename UID GID

Requests that the server change the owner and group of the file specified by filename to those provided as decimal numeric arguments UID and GID . Works only if the server supports Unix CIFS extensions.

cd [directory]

With no argument, prints the current working directory on the remote system. If a directory name is supplied as an argument, changes the working directory on the remote system to that specified.

del filename

Requests that the server delete one or more files, as specified by the argument, from the current working directory. The argument can be a filename globbing pattern using the * and ? characters .

dir [ filename]

With no arguments, prints a list of files and directories in the working directory on the server. If an argument is provided, only files and directories whose names match the argument will be listed. The argument can be a filename globbing pattern using the * and ? characters.

exit

Quits the smbclient program after terminating the SMB connection to the server.

get remote_file [local_file]

Copies the file specified by remote_file from the server to the local system. If no local_file argument is specified, smbclient will name the local file the same as it is named on the server. If local_file is specified, it will be used as the name of the local copy. See also the lowercase command.

help [command]

A synonym for the ? command.

lcd [directory]

If no argument is provided, prints the name of smbclient 's working directory on the local system. If a directory name is provided as an argument, changes smbclient 's working directory to the directory specified.

link link_name filename

Requests that the server create a hard link to filename and name it link_name . This command works only if the server supports Unix CIFS extensions.

lowercase

Toggles the boolean lowercasing setting. When this setting is on, names of files copied from the server with the get and mget commands will be changed to all lowercase. This is mainly used for accessing servers that report filenames in all uppercase only.

ls [filename]

A synonym for dir .

mask [globbing_pattern]

Sets the filename globbing pattern for use with the mget and mput commands when recursion is turned on. (When recursion is off, the setting has no effect.) Both mget and mput accept a globbing pattern as arguments; however, those patterns apply only to the current directory. This command specifies the pattern used for all subdirectories that are recursively traversed. The pattern stays in effect until it is changed with another mask command. To return the setting to its original default, specify a globbing_pattern of an asterisk ( * ), which matches all files. See also the mget , mput , and recurse commands.

mdir directory

A synonym for the mkdir command.

mget pattern

When recursion is turned off, copies files matching the file-globbing pattern, as specified by the argument, from the current working directory on the server to the local system. When recursion is on, the pattern argument is used to match directories in the current working directory, and the pattern specified by the mask command is used for matching files within each directory and all subdirectories. See also the lowercase , mask , and recurse commands.

print filename

Prints the specified file. This requires that smbclient be connected to a print share. See also the printmode command.

printmode mode

Sets the mode that is used by the print command. The mode can be either text , for printing text files such as the ASCII files commonly found on Unix, or graphics , for printing binary files.

prompt

Toggles the prompting mode. When prompting is on (the default), the mget and mput commands will interactively prompt the user for permission to transfer each file. The user can answer either y (yes) or n (no), followed by a newline, to this prompt. When prompting is off, all the files will be transferred with no prompts issued.

put local_file [remote_file]

Copies the file specified by local_file from the local to the remote system. If no remote_file argument is specified, smbclient will name the remote file the same as it is named on the local system. If remote_file is specified, it will be used as the name of the remote copy. See also the lowercase command.

queue

Prints information on the print queue on the server. This requires that smbclient is connected to a print share.

quit

A synonym for exit .

rd directory

A synonym for rmdir .

recurse

Toggles the recursion mode, which affects the mget and mput commands. When recursion is off (the default), the mget and mput commands will copy only files from the current working directory that match the file-globbing pattern specified as an argument to the command, and the pattern set by the mask command is ignored. When recursion is turned on, the mget and mput commands recursively traverse any directories that match the pattern specified as the argument to the command, and the pattern set by the mask command is used to match files in those directories.

rm filename

A synonym for del .

rmdir directory

Requests that the server remove the specified directory.

setmode filename attributes

Requests that the server assign the specified MS-DOS file attributes on the specified file. The attributes argument has the format of a leading plus sign ( + ) or minus sign ( - ) either to set or to unset the attribute(s), respectively, followed by one or more of the characters r (read), s (system), h (hidden), or a (archive).

symlink link_name filename

Requests that the server create a symbolic link named link_name to filename . This command works only if the server supports Unix CIFS extensions. The server will not create a link that refers to a file not in the share to which smbclient is connected.

tar cmd_str

Performs an archiving operation using the tar format. This is the interactive form of the -T command-line operation, and the cmd_str argument is specified in the same manner. See also the tarmode command.

blocksize size

Sets the block size, in units of 512 bytes, for files written by the tar command.

tarmode mode ...

Specifies how the tar command performs its archiving, including how it handles the archive attribute on files. Multiple mode arguments can be provided, chosen from the following:

full

All files will be included, regardless of whether their archive attribute is set. This is the default.

inc

Only files that have the archive attribute set will be included in the backup.

reset

The archive attribute will be unset by tar after the file is included in the archive.

noreset

The archive attribute will be left unchanged. This is the default.

system

Files with the system attribute set will be included in the archive. This is the default.

nosystem

Files with the system attribute set will not be included in the archive.

hidden

Files with the hidden attribute set will be included in the archive. This is the default.

nohidden

Files with the hidden attribute set will not be included in the archive.

verbose

As files are included in the archive (when creating the archive) or are read from the archive (when extracting it), the name of each file will be printed. This is the default.

noverbose

This turns verbose mode off, causing tar to perform its work quietly .

quiet

An antonym for the verbose mode. When quiet is on, verbose is off, and vice versa.

   


Using Samba
Using Samba: A File and Print Server for Linux, Unix & Mac OS X, 3rd Edition
ISBN: 0596007698
EAN: 2147483647
Year: 2003
Pages: 475

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