Copying folder to NAS drive using terminal

40,402

You cannot cd to a smb share like this.
Nautilus/Nemo can do that, because it uses a virtual file system (gvfs) in the background and mounts the share to a folder somewhere in your file system automatically.

After you fired Nautilus/Nemo to mount it, you could go to /run/user/1000/gvfs/[...] (compare your mount output) and voilà. You should see the smb share there.


From the terminal without Nautilus/Nemo you need to mount the smb drive manually. There are several options doing so.

Most common option afaik is using cifs. smbfs is an alternative. Alternatives for mounting smb in userspace (without the need of having sudo rights or being root) are described here or here or here.

Install cifs-utils:

sudo apt-get install cifs-utils

Then mount your drive

--> either temporarily:

sudo mount -t cifs -o <Options> //<Server>/<Sharename> <Mountpoint> 

Note: <MountPoint> must exist.

e.g.

sudo mount -t cifs -o credentials=~/.smbcredentials //nas/shared_folder /media/nas_shared

with ~/.smbcredentials being just a regular text file with following content:

username=<username of the share>
password=<password of the share>

Leave out the -o credentials=[...] part if it's a public share without login.

--> or permanent using fstab:

//<Server>/<Sharename> <Mountpoint> cifs credentials=/home/user/.smbcredentials  0 0

Then you can cd to <Mountpoint>.


Get more information from the Ubuntu WIKI.

Share:
40,402

Related videos on Youtube

Adam
Author by

Adam

Updated on September 18, 2022

Comments

  • Adam
    Adam over 1 year

    Hello so I'm completely new to Ubuntu and I wanted to copy folders to my network drive. I understand how to copy files normally but I can't seem to copy over files to my network drive.

    sudo cp /home/adam/file.txt smb://nas/main/
    

    It says no such directory exists. I can navigate to the location through the file explorer.

    EDIT2: Solution provided by RoVo works. I mounted the network drive permanently by editing the /etc/fstab file and adding the line to the end.

    I can now transfer files with:

    sudo cp /home/adam/file.txt /media/networkdrive
    
    • Mahesh K K
      Mahesh K K almost 7 years
      Navigate to the folder main and check path from properties and see if it matches in your command.
    • Laice
      Laice almost 7 years
      Hi Adam, could you run "lsblk" and "mount" from the command line and pastebin the results for me?
    • terdon
      terdon almost 7 years
      Please edit your question and add the output of the commands Laice requested. Make sure you run the after navigating to the location through the file explorer.
    • Adam
      Adam almost 7 years
      @terdon I've ran the commands and edited the results into the post.
    • terdon
      terdon almost 7 years
      Woah, wait. You say it's running in a VM in your NAS!? What OS is this? What is the guest OS, what is the host OS, which OS is giving you access to the network drive? Also, what is /media/ubvi/Ubuntu 16.04.2 LTS? Is that a mounted CD or is that your network drive? How is this "network drive" set up?
    • terdon
      terdon almost 7 years
      OK, please edit your question and clarify that. Comments are hard to read and easy to miss and can be deleted without warning. Also clarify whether it is the host or the guest that needs to see the drive and what operating system host and guest are running. That said, assuming the OS that needs to see the drive is running Ubuntu, the answer below should work.
  • Adam
    Adam almost 7 years
    What username and password is required? The drive is public on the network. When I try to mount it temporarily it gives me a mount error(6): No such device or address
  • pLumo
    pLumo almost 7 years
    The ones of the Shared Folder of the NAS. Not needed if its open share. Then leave it out