1

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?

6
  • 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. Commented 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'. Commented 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. Commented 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! Commented 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). Commented Aug 18, 2019 at 6:08

1 Answer 1

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
5
  • 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 Commented Aug 19, 2019 at 3:50
  • Any other idea? Commented 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? Commented Aug 20, 2019 at 12:32
  • No, did you run your command successfully ? Commented 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" "//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. Commented Aug 20, 2019 at 14:32

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.