On Linux, you’ll need the following (verified on Ubuntu 18.04, albeit not with a Windows domain account):
Prerequisite: The
cifsutil
package must be installed, which the script below ensures (it callssudo apt-get install cifs-utils
on demand).Choose a (temporary) mount point (a local directory through which the share’s files will be accessible).
Use the
mount.cifs
utility to mount your share, andumount
to unmount (remove) it later.Use
cp -R
to copy a directory hierarchy.
Note:
sudo
(administrative) privileges are required; the script will prompt once for a password, which is normally cached for a few minutes.
#!/bin/sh
# The SMB file-share path given as an argument.
local mypath=$1
# Choose a (temporary) mount-point dir.
local mountpoint="/tmp/mp_$$"
# Prerequisite:
# Make sure that cifs-utils are installed.
which mount.cifs >/dev/null || sudo apt-get install cifs-utils || exit
# Create the (temporary) mount-point dir.
sudo mkdir -p "$mountpoint" || exit
# Mount the CIFS (SMB) share:
# CAVEAT: OBVIOUSLY, HARD-CODING A PASSWORD IS A SECURITY RISK.
sudo mount.cifs -o user= "user=user,pass=myPassword123!,domain=somedomain" "$mypath" "$mountpoint" || exit
# Perform the copy operation
# Remove the `echo` to actually perform copying.
echo cp -R . "$mountpoint/"
# Unmount the share.
sudo umount "$mountpoint" || exit
# Remove the mount-point dir., if desired
sudo rmdir "$mountpoint"
CLICK HERE to find out more related problems solutions.