In past OSX versions, one could copy files from SMB shares like so:

smbclient //my-server/foo -U USER%PASS -I -c "get my.file" 

However, in recent versions, sbmclient has been replaced with smbutil which does not have copying capabilities. As far as I can tell, the only replacement is mount -t smbfs. I am not aware of any way to install smbclient on OSX (Print file from terminal via smb).

Mounting is pretty annoying though:

  1. You have to create a folder for the mount point (what if it already exists?)
  2. If the same folder has already been mounted on a different folder, mount will fail (with a pretty misleading error)
  3. There's no "structured" way to tell which shares are mounted where (that I know of), meaning you'll have to grep/sed the output of df to try and work around the issues above

Basically I just want to reliably copy a file from an SMB share in a bash script, and the issues above make it more complicated than it should be (and already was before smbclient was dropped).

  • [ -d /path/to/dir ] tests whether a folder exists already, mount lists all mounted shares/drives. Combined in a shell script this should take care of all three issues. – nohillside Jan 25 '17 at 17:59
  • @patrix yes and now you have to parse mount's output with regular expressions which may be tricky as domain and user information might be there (in different casing and maybe even differently qualified domain names, not sure). And you have to have different logic for whether it's already mounted or not, and probably add some echo calls that explain what's going on etc. All that instead of one simple smbclient command. – Ohad Schneider Jan 25 '17 at 19:11
  • That's what shell scripts and programming are for :-) But of course, smbclient would have been simpler. – nohillside Jan 25 '17 at 22:40
  • @patrix indeed, hence this question :) – Ohad Schneider Jan 26 '17 at 8:52
  • I would go with a script (but you would need to add more details to your question if you want me to write something :-)) – nohillside Jan 26 '17 at 9:16

You must log in to answer this question.

Browse other questions tagged .