We need to install Samba to get smbclient(1) .
pkg install samba47
Notes:
Let's define some environmental variables first.
authfile="$HOME/smbclient-authentication-file.txt" smb_username='0mp' smb_password='secret' max_protocol='SMB2' workgroup='CORP' service='\\shareserver\importantfolder'
Also, let's use a variable to refer to the smbclient(1) command invocation with the default set of arguments:
smb_client="smbclient --max-protocol=${max_protocol} --workgroup=${workgroup} ${service}"
First the smb4.conf file has to exist. Otherwise smbclient(1) fails with:
smbclient: Can't load /usr/local/etc/smb4.conf - run testparm to debug it
It is enough to run the following command:
touch /usr/local/etc/smb4.conf
Now let's create a file to store authentication details. The username and the password may also be provided as command line arguments.
touch "${authfile}" chmod 0600 "${authfile}" printf 'username = %s\n' "${smb_username}" > "${authfile}" printf 'password = %s\n' "${smb_password}" > "${authfile}"
Run smbclient(1):
${smb_client}
You should now see a prompt similar to this:
Try "help" to get a list of possible commands. smb: \>
smbclient(1) behaves similarly to ftp(1) in the sense that it starts an interactive shell session.
It is possible to use smbclient(1) in non-interactive scripts.
Here's an example of downloading a file from the share:
echo get '\Files\file.txt' 'file.txt' | ${smb_client}
Here's an example of saving (uploading) a file to the share:
echo put './file.txt' | ${smb_client}
As of 2020-11-02…