I was wondering if there is a way to use Samba to send items to a client machine via the command line (I need to send the files from the Samba server). I know I could always use
scp but first I was wondering if there is a way to do it with Samba. Thanks!
curl supports the
smb v1 protocol since v7.40:
curl --upload-file /path/to/file.ext -u 'DOMAIN\Username' smb://172.16.17.52/ShareName/
SMB v1 is not available by default in Windows anymore so this won't work with current Windows shares in their default configuration.
smbclient, a program that comes with Samba:
$ smbclient //server/share -c 'cd c:/remote/path ; put local-file'
There are many flags, such as
-U to allow the remote user name to be different from the local one.
On systems that split Samba into multiple binary packages, you may have the Samba servers installed yet still be missing
smbclient. In such a case, check your package repository for a package named
samba-client, or similar.
The easiest way I found is using smbget
If authentication is needed (if password is not provided, it will prompt for password):
smbget smb://PATH/TO/FILE/test.txt -U "email@example.com%myPassword"
You can also specify where to save the file and the name of the file after copy:
smbget smb://PATH/TO/FILE/test.txt -U "firstname.lastname@example.org%myPassword" -o /LINUX/PATH/remote_test_file
Another way if the share is already mounted by fuse
If you are running some desktop with shares already mounted by nautilus, caja or any other file manager, you could be using fuse (instead of smbclient).
If so, you may find some mountpoints at:
ls -l /run/user/$UID/gvfs/ drwx------ 1 charlie charlie 0 Feb 2 10:04 smb-share:server=hostname,share=documents
Yes this is a mountpoint!
df -h /run/user/$UID/gvfs/* Filesystem Size Used Avail Use% Mounted on gvfsd-fuse 16.2T 3.6T 12.6T 59% /run/user/1000/gvfs
And you could use it as a regular filesystem.
cp $HOME/myfile \ /run/user/$UID/gvfs/smb-share:server=hostname,share=documents/destpath/