0

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" "//192.168.1.1/share"
Domain=[mydomain] OS=[Windows Server] Server=[Windows Server]
/data/directory does not exist
[user@host home]$ cd /data/directory
/data/directory
[user@host directory]$ ll
File1
File2
..

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 '19 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 '19 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 '19 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 '19 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 '19 at 6:08
1

If you want to copy /data/directory on Linux so that a copy of it will appear as \\192.168.1.1\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" "//192.168.1.1/share"

Rationale:

  • 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 \\192.168.1.1\share\data\directory but just \\192.168.1.1\share\directory
| improve this answer | |
  • seems not work! [user@host home]$ smbclient -W WORKGROUP --user='admin%admin$123' -c "lcd /data;recurse;mput directory" "//192.168.1.1/share" -bash: recurse: command not found -bash: mput: command not found – Mehrdad Aug 19 '19 at 3:50
  • Any other idea? – Mehrdad Aug 20 '19 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 '19 at 12:32
  • No, did you run your command successfully ? – Mehrdad Aug 20 '19 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" "//192.168.1.1/share". 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 '19 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.