Want to copy directory from linux machine to windows (SMB) with shell script.

[user@host home]$ smbclient -W WORKGROUP --user='admin%admin$123' -c "put /data/directory" "//"
Domain=[mydomain] OS=[Windows Server] Server=[Windows Server]
/data/directory does not exist
[user@host home]$ cd /data/directory
[user@host directory]$ ll

Here is the issues:

  • Not accept password even when I use (-N)

  • even try this --user=admin%admin$123

When I remove password from command and shell ask me password it works!

FYI: for transferring directory between Windows and Linux I read about curl, and SSH daemon on windows for scp, do you have any recommendation or simple way, without require additional service on Windows or package on Linux?

  • 2
    I guess the and characters in your code used to be ", while the characters were originally -. Am I right? If so, please edit your question, replacing the characters that were not in the command you actually tried. It will help other users in ruling out possible issues.
    – fra-san
    Aug 16, 2019 at 14:29
  • 1
    1) Are you sure your smbclient accepts a --pass option? (My does not). 2) Your issue may depend on the characters in your password (e.g $). You should single-quote the password string, to input it literally, or double-quote it, if you store it in a variable. Possibly --user='admin%admin$123'.
    – fra-san
    Aug 16, 2019 at 15:37
  • 1-in address of source file I have under score _ , how can I define addresses like this? Would you please write simple example of my command.
    – Mehrdad
    Aug 16, 2019 at 20:53
  • 2-you right read man of smbclient not mention about it. I try user='admin%admin$123' seems work, but seems not get my source address and give me not find source address!
    – Mehrdad
    Aug 16, 2019 at 20:57
  • Please, edit you question and add it the exact error message you are seeing. If possible, copy/paste both it and the full command you are trying (after obfuscating sensitive parts as passwords, of course).
    – fra-san
    Aug 18, 2019 at 6:08

1 Answer 1


If you want to copy /data/directory on Linux so that a copy of it will appear as \\\share\directory on Windows, then perhaps this command should do the job:

smbclient -W WORKGROUP --user='admin%admin$123' -c "lcd /data;recurse;mput directory" "//"


  • to copy a directory with its contents, you'll need to enable recursion with recurse and use mput as you will be copying multiple files. The regular put command will only transfer one file at a time, optionally giving the copy a different name at the destination.
  • by first using lcd, the recursion is limited so that the copy won't become \\\share\data\directory but just \\\share\directory
  • seems not work! [user@host home]$ smbclient -W WORKGROUP --user='admin%admin$123' -c "lcd /data;recurse;mput directory" "//" -bash: recurse: command not found -bash: mput: command not found
    – Mehrdad
    Aug 19, 2019 at 3:50
  • Any other idea?
    – Mehrdad
    Aug 20, 2019 at 12:28
  • The error message indicates the recurse and mput commands were somehow handled by the bash shell, not by the smbclient command. Did you accidentally omit a quote character at some point?
    – telcoM
    Aug 20, 2019 at 12:32
  • No, did you run your command successfully ?
    – Mehrdad
    Aug 20, 2019 at 13:18
  • 1
    Yes, I did. If your version of smbclient starts displaying prompts like Put directory directory?, you'll need to add prompt; to the -c command string before the mput, i.e. $ smbclient -W WORKGROUP --user='admin%admin$123' -c "lcd /data;recurse;prompt;mput directory" "//". It is important that the argument to the -c option is quoted, as the semi-colon is a command separator for the shell. Your error message indicates the shell parsed everything up to the first semicolon as one command, recurse as another command etc. So you failed to quote the option argument.
    – telcoM
    Aug 20, 2019 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.