「smbclient」

smbclient,用于访问 Server 上的资源的像 ftp 一样的客户端。

命令行语法格式(SYNOPSIS)

smbclient [-b <buffer size>] [-d debuglevel] [-e] [-L <netbios name>] [-U username] [-I destinationIP]
[-M <netbios name>] [-m maxprotocol] [-A authfile] [-N] [-C] [-g] [-i scope] [-O <socket options>] [-p port]
[-R <name resolve order>] [-s <smb config file>] [-t <per-operation timeout in seconds>] [-k] [-P]
[-c <command>]

smbclient {servicename} [password] [-b <buffer size>] [-d debuglevel] [-e] [-D Directory] [-U username]
[-W workgroup] [-M <netbios name>] [-m maxprotocol] [-A authfile] [-N] [-C] [-g] [-l log-basename]
[-I destinationIP] [-E] [-c <command string>] [-i scope] [-O <socket options>] [-p port]
[-R <name resolve order>] [-s <smb config file>] [-t <per-operation timeout in seconds>] [-T<c|x>IXFqgbNan]
[-k]

命令简述(DESCRIPTION)

该命令是 samba(7)套件的一部分。

smbclient 用于与 SMB/CIFS Server 进行“交流”。它提供了类似于终端下的 ftp(1)程序的界面。支持的操作包括从服务器获取文件到本地机器,将文件从本地机器上传到服务器,从服务器检索目录信息等等。

命令支持的选项及含义(OPTIONS)

servicename
servicename是要在server上使用的service的描述。servicename采用//server/service的形式:其中server是提供所需服务的 SMB/CIFS Server 的NetBIOS Nameservice是所提供服务的名称;
因此,要连接到名为“smbserver”的 SMB/CIFS Server 上的“printer”服务,servicename的格式为://smbserver/printer

注意,所需的server不一定是服务器的 IP(DNS)主机名!所需的名称是 Server 的NetBIOS Name,NetBIOS Name 可能与计算机的 IP 主机名相同,也可能不相同。

根据「smbclient 的-R 指定的参数」「smb.conf(5)文件中的 name resolve order 指定的参数」来进行查找server 名称,允许管理员更改查找server 名称的顺序和方法。

password
The password required to access the specified service on the specified server. If this parameter is
supplied, the -N option (suppress password prompt) is assumed.

There is no default password. If no password is supplied on the command line (either by using this
parameter or adding a password to the -U option (see below)) and the -N option is not specified, the
client will prompt for a password, even if the desired service does not require one. (If no password is
required, simply press ENTER to provide a null password.)

Note: Some servers (including OS/2 and Windows for Workgroups) insist on an uppercase password. Lowercase
or mixed case passwords may be rejected by these servers.

Be cautious about including passwords in scripts.

-R|–name-resolve <name resolve order>
在 Samba 套件中的程序,使用此选项来确定「哪些命名服务」以及「以什么顺序」将 NetBIOS Name 解析为 IP 地址。该选项采用不同名称解析选项的空格分隔的字符串。
<name resolve order>的格式为空格分隔的多个选项。

支持的选项:”lmhosts”, “host”, “wins”, “bcast”。这些选项使 NetBIOS Name 按如下进行所述进行解析:

  • lmhosts: 在 Samba 的 lmhosts 文件中查找 IP 地址。如果 lmhosts 中的行没有绑定到 NetBIOS Name 的名称类型(参阅 lmhosts(5)),然后查找任何名称类型。
  • host: 使用系统 /etc/hosts、NIS、DNS 查找来执行主机名到 IP 地址解析。这种名称解析方法是依赖于操作系统的,例如在 IRIX 或 Solaris 上,这可以由 /etc/nsswitch.conf 文件控制)。注意,仅当正在查询的 NetBIOS Name 类型为 0x20(server)的名字类型时,才使用此方法,否则将被忽略。
  • wins: 使用 wins server 参数中列出的 IP 地址来查询名称。如果没有指定 WINS 服务器,则此方法将被忽略。
  • bcast:在interfaces参数中列出的每个已知的本地接口上进行广播。这是名称解析方法中最不可靠的,因为它取决于目标主机在本地连接的子网上。

如果未设置此参数,则将使用 smb.conf(5)文件中参数(name resolve order)中定义的名称解析顺序。

默认的顺序是 lmhosts,host,wins,bcast。如果没有使用-R 并且没有在 smb.conf(5)文件的的name resolve order参数指定任何条目,将按此顺序尝试名称解析方法。

问题诊断(DIAGNOSTICS)

Client 发出的大多数诊断都记录在指定的日志文件中。日志文件名是在编译时指定,但可能在命令行上进行覆盖。

诊断可用的数量和性质取决于 Client 使用的调试级别。如果有问题,请将调试级别设置为 3,并仔细阅读日志文件。

文档版本(VERSION)

原文 “This man page is correct for version 3.2 of the Samba suite.”

该文档对于 3.2 版本的 Samba 套件是正确的。我使用的 Samba 的版本是 4.6.5,从发行版的源中直接安装的,似乎发行版的文档并没有更新。

后来,我们又去官网找了一通:
https://www.samba.org/samba/docs/man/manpages/smbclient.1.html
https://www.samba.org/samba/docs/man/manpages-3/smbclient.1.html
似乎也都是这个样子,所以可能 smbclient 没有什么更新吧。

参考

  • man 1 smbclient, version Version 4.6.5-Debian