How do I recursively download a directory using smbclient?

25

9

When I try to fetch a directory with get "Path To\Directory\", I get the following error:

NT_STATUS_FILE_IS_A_DIRECTORY opening remote file Path To\Directory

How do I recursively download this directory?

(Using smbclient v3.6.23. The server is a computer running Windows 7 Home Edition.)

hololeap

Posted 2014-12-25T00:49:59.747

Reputation: 951

smbclient uses the same type of semantics that server clients like FTP and HTTP do, where each get or put targets one file. you can write scripts to perform retrievals by directory, or you can use the mget/mput commands to specify a mask or wildcard to retrieve multiple files, as shown in my answer. it may be that smbclient isn't quite the right tool for your purposes. – Frank Thomas – 2014-12-25T04:23:01.243

Answers

54

per the smbclient manpage, you need to use the mget command, with a mask and recursion and prompt set. Then cd to the directory you want to get recursively

    smbclient '\\server\share'
    mask ""
    recurse ON
    prompt OFF
    cd 'path\to\remote\dir'
    lcd '~/path/to/download/to/'
    mget *

or, all on one line,

smbclient '\\server\share' -N -c 'prompt OFF;recurse ON;cd 'path\to\directory\';lcd '~/path/to/download/to/';mget *'

if you need to authenticate to the server drop -N and use the Password setting on the connect command.

http://technotize.blogspot.com/2011/12/copy-folder-with-ubuntu-smb-client.html

Frank Thomas

Posted 2014-12-25T00:49:59.747

Reputation: 29 039

2Also, I think you've got your quotes a bit confused in the one-liner. My smbclient only seems to like dealing with directories in "double quotes". – c24w – 2017-06-07T14:32:50.877

Just copied and replaced folders but it didnt work - ends with trailing > – Wax Cage – 2017-08-07T21:40:39.757

For people really want to copy without problems follow this article: https://indradjy.wordpress.com/2010/04/14/getting-whole-folder-using-smbclient/ (helped me)

– Wax Cage – 2017-08-07T21:46:08.127

0

use -D option to set the Directory

smbclient -D "\" -c ls
smbclient -D "\Path\To\Directory" -c ls

if you want to download/get the file, do

smbclient -D "\Path\To\Directory" -c "get target /tmp/target"

aGuegu

Posted 2014-12-25T00:49:59.747

Reputation: 101

0

You could also use the tar command for smbclient:

smbclient -Tc allfiles.tar /path/to/directory

This will create a tar archive allfiles.tar in the current directory the smbclient command is executed. Afterwards you can unpack the files again with tar xf allfiles.tar.

m13r

Posted 2014-12-25T00:49:59.747

Reputation: 101