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\DirectoryHow do I recursively download this directory?
(Using smbclient v3.6.23. The server is a computer running Windows 7 Home Edition.)
14 Answers
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.
use -D option to set the Directory
smbclient -D "\" -c ls
smbclient -D "\Path\To\Directory" -c lsif you want to download/get the file, do
smbclient -D "\Path\To\Directory" -c "get target /tmp/target" You could also use the tar command for smbclient:
smbclient -Tc allfiles.tar /path/to/directoryThis 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.
In addition to one-liner above, I found a solution for Teamcity with hidden password prompt (build step written as a command, TC version 2020.1.2):
smbclient '%smbPath%' '%smbPassword%' -W %domain% -U %smbUser% -c 'prompt OFF; recurse OFF; cd %smbSource%; lcd tomcat/conf; mget *'where
%smbPath% = \\smbserver\share
%smbPassword% = domain user's password, use single quotes
%domain% = domain
%smbUser% = username
%smbSource% = subdirectory(-ies) inside samba share (i.e. -D option)
recurse OFF = in my case I don' want to recurse subfolders
tomcat/conf = destination path relative to %system.teamcity.build.tempDir% (i.e. working directory) It will download all files from samba directory to working directory on build agent. The most problem here is the proper quotation of a password. The password containing @, # should be written separately from username. Escaping mode %smbUser%%%%smbPassword% may not work.