LinuxCommandLibrary

smbget

Download files from SMB/CIFS shares

TLDR

Download a file from a server

$ smbget [smb://server/share/file]
copy

Download a share or directory recursively
$ smbget --recursive [smb://server/share]
copy

Connect with a username and password
$ smbget [smb://server/share/file] [[-U|--user]] [username%password]
copy

Require encrypted transfers
$ smbget [smb://server/share/file] [[-e|--encrypt]]
copy

SYNOPSIS

smbget [options] URL

PARAMETERS

-b
    Binary transfer mode (default).

-d DEBUGLEVEL
    Set debug level (0-10).

-h
    Display help and exit.

-n
    No prompt. Useful for scripts.

-o filename
    Output filename. If not specified, the filename from the URL will be used.

-r
    Recursive mode. Download directories and their contents.

-R
    Resume incomplete downloads.

-U username[%password]
    Username for authentication. Password may be specified or prompted for.

-v
    Verbose mode.

-V
    Print version information and exit.

DESCRIPTION

The smbget command is a versatile tool used to download files and directories from SMB/CIFS (Server Message Block/Common Internet File System) shares, commonly used on Windows networks. It acts as a simple wget-like utility but specifically designed for SMB/CIFS protocols. Unlike more complex tools like `smbclient`, smbget provides a streamlined way to retrieve files without requiring interactive sessions or elaborate configurations for basic file retrieval.
It's often employed in scripts or automated tasks where fetching files from an SMB share is a necessity. smbget uses the credentials from the user executing the command, or can take specific credentials.
The tool supports features like automatic filename generation, recursive directory downloading, and authentication options. The command is usually available within the `samba` packages or a related samba client suite.

CAVEATS

smbget requires the `samba-client` package to be installed. It may not be as robust as `smbclient` for complex scenarios or when handling very large file transfers. Ensure the SMB share is properly configured with appropriate permissions to avoid access errors.
URL must be a valid SMB share URL. Check the URL format before execution.
When using the recursive option be mindful of large directories since smbget reads all files and directories at once and may run into resource limitations.

URL FORMAT

The URL should be in the form: smb://server/share/path/to/file. For example: smb://example.com/public/mydata.txt

SEE ALSO

smbclient(1), wget(1), curl(1)

Copied to clipboard