Search code examples
shellftpsmb

Transferring the Contents of a Folder Using smbclient


I have written a Shell script that moves into a directory with some binaries files present.

What I am looking to do is transfer all the files present inside this directory.

cd /home/user/binaries
smbclient //ip.address/directory$ password -W domain -U username << ENDOFMYSMBCOMMANDS
prompt
put *
exit
ENDOFMYSMBCOMMANDS

I tried to use put * to transfer all files - but this is not accepted.

The only other option I know of is to go one folder up, and use the command mput binaries - but this copies everything including the folder.

How can I modify my script to only transfer the contents of the directory?


Solution

  • I had the answer with me all along!! I was under the impression that mput could only be used to transfer a directory, turns out that using mput * inside a directory will copy all the files located within that directory!

    cd /home/user/binaries
    smbclient //ip.address/directory$ password -W domain -U username << ENDOFMYSMBCOMMANDS
    prompt
    put *
    exit
    ENDOFMYSMBCOMMANDS
    

    Going to leave this here for anyone else who gets stumped on this like me!