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] smb://[[<domain>;]<username>[:<password>]@]<server>[/<share>[/<path/to/file>]]

PARAMETERS

-a, --archive
    Only retrieve files with the archive bit set on the source.

-E, --delete-source
    Delete the source file on the SMB share after successful transfer.

-L, --list
    List the contents of the specified SMB directory without downloading any files.

-P, --preserve-times
    Preserve the modification times of the retrieved files, setting them to match the source.

-R, --recursive
    Recursively download files and subdirectories from the specified SMB share.

-p password, --password=password
    Specifies the password for authentication. If not provided, smbget might prompt for it interactively.

-U username, --user=username
    Specifies the username for authentication when connecting to the SMB share.

-W workgroup, --workgroup=workgroup
    Specifies the workgroup or domain for the user account used for authentication.

-N, --no-pass
    Prevents smbget from asking for a password, useful for anonymous or guest access.

-v, --verbose
    Increases the verbosity of smbget's output, showing more details about the transfer process.

-X, --anonymous
    Attempts to connect to the SMB share using anonymous (guest) access.

DESCRIPTION

smbget is a command-line tool included in the Samba suite, designed to download files or entire directories from an SMB/CIFS network share. It functions similarly to wget but is tailored specifically for the Server Message Block (SMB) protocol, widely used by Microsoft Windows for file sharing. smbget supports various authentication methods, including username/password, and can connect to shares using either the server's IP address or hostname.

It's particularly useful for scripting and automation, allowing administrators and users to programmatically fetch content from Windows file servers or Samba shares without needing a graphical interface. It handles common SMB features like NTLM authentication, anonymous access, and can specify the workgroup or domain. Its simple syntax makes it efficient for quick file transfers in heterogeneous network environments.

CAVEATS

Providing sensitive information like passwords directly on the command line using -p or within the URL can be a security risk, as it may be visible in process lists (ps) or command history. smbget does not inherently support resuming interrupted downloads, unlike tools such as wget. Its functionality for MD5 verification is dependent on the SMB server's support for the feature. Performance can vary significantly based on network conditions and server capabilities.

SMB URL SYNTAX

The SMB_URL is the primary way to specify the target resource for smbget. Its general format is:
smb://[[<domain>;]<username>[:<password>]@]<server>[/<share>[/<path/to/file>]].
<server> can be an IP address or hostname. <share> is the name of the shared resource, and <path/to/file> specifies the exact file or directory within that share. While user credentials (username, password, domain) can be embedded directly in the URL, using command-line options (-U, -p, -W) or allowing smbget to prompt for them is generally considered more secure.

HISTORY

smbget is an integral part of the Samba suite, a project initiated in 1992. It was developed to provide a command-line interface for retrieving files from SMB/CIFS shares, mirroring the utility of tools like wget but specifically for the SMB protocol. This enabled non-interactive and scriptable file transfers from Windows and Samba servers. As the SMB protocol evolved with versions like SMB2 and SMB3, smbget's underlying Samba libraries have been continuously updated to support these advancements, ensuring its relevance and functionality in modern heterogeneous network environments. It remains a vital tool for automated file operations in Linux/Unix systems interacting with Windows file shares.

SEE ALSO

Copied to clipboard