1.14. Using the smbclient utility to access an SMB share
The smbclient utility enables you to access file shares on an SMB server, similarly to a command-line FTP client. You can use it, for example, to upload and download files to and from a share.
1.14.1. Prerequisites 复制链接链接已复制到粘贴板!
-
The
samba-clientpackage is installed.
1.14.2. How the smbclient interactive mode works 复制链接链接已复制到粘贴板!
The interactive mode of smbclient enables users to connect to SMB/CIFS shares, navigate files and directories, and execute common file operations securely from the command line using various built-in commands.
For example, to authenticate to the example share hosted on server using the DOMAIN\user account:
# smbclient -U "DOMAIN\user" //server/example
Enter domain\user's password:
Try "help" to get a list of possible commands.
smb: \>
After smbclient connected successfully to the share, the utility enters the interactive mode and shows the following prompt:
smb: \>
To display all available commands in the interactive shell, enter:
smb: \> help
To display the help for a specific command, enter:
smb: \> help command_name
1.14.3. Using smbclient in interactive mode 复制链接链接已复制到粘贴板!
If you use smbclient without the -c parameter, the utility enters the interactive mode. The following procedure shows how to connect to an SMB share and download a file from a subdirectory.
Procedure
Connect to the share:
# smbclient -U "DOMAIN\user_name" //server_name/share_nameChange into the
/example/directory:smb: \> d /example/List the files in the directory:
smb: \example\> ls . D 0 Thu Nov 1 10:00:00 2018 .. D 0 Thu Nov 1 10:00:00 2018 example.txt N 1048576 Thu Nov 1 10:00:00 2018 9950208 blocks of size 1024. 8247144 blocks availableDownload the
example.txtfile:smb: \example\> get example.txt getting file \directory\subdirectory\example.txt of size 1048576 as example.txt (511975,0 KiloBytes/sec) (average 170666,7 KiloBytes/sec)Disconnect from the share:
smb: \example\> exit
1.14.4. Using smbclient in scripting mode 复制链接链接已复制到粘贴板!
If you pass the -c parameter to smbclient, you can automatically execute the commands on the remote SMB share. This enables you to use smbclient in scripts.
The following procedure shows how to connect to an SMB share and download a file from a subdirectory.
Procedure
Use the following command to connect to the share, change into the
exampledirectory, download theexample.txtfile:# smbclient -U DOMAIN\user_name //server_name/share_name -c "cd /example/ ; get example.txt ; exit"