Post

Transferring files over LAN

Transferring files over LAN

Problem

I host my NC instance through cloudflare tunnel. However, if I want to transfer something through my LAN instead of over the internet, nextcloud does not have a native solution for that.

Solution

Here is my thought process:

  1. Since my nextcloud data drive is just an NFS share from TrueNAS Core, I should be able to mount it on my PC and transfer files that way
  2. After that, the file should magically appear in my nextcloud instance… right?

Problem 1: Mounting NFS share on Windows

Since my files are on my Windows PC, I cannot mount NFS share directly like I can with SMB. Of course, the logical solution would be to use WSL2.

To even mount NFS shares, there are several steps to be performed:

  1. Download nfs-common (Reference: https://www.truenas.com/docs/scale/23.10/scaletutorials/shares/addingnfsshares/#connecting-to-the-nfs-share)
    1
    
    sudo apt install nfs-common
    
    • If you try to mount the share now, there would likely be this error:
      1
      2
      
      mount.nfs: rpc.statd is not running but is required for remote locking.
      mount.nfs: Either use '-o nolock' to keep locks local, or start statd.
      
  2. Run the following commands
    1
    2
    
    sudo /etc/init.d/rpcbind start
    sudo /etc/init.d/nfs-common start
    
    • After which, trying to mount again would give a permission error
      1
      
      mount.nfs: access denied by server while mounting ...
      
  3. On TrueNAS, Click Services –> NFS (pencil icon) –> Allow non-root mount
    • You should now be able to mount the nextcloud data drive

Problem 2: Making files appear in the nextcloud instance

After mounting the NFS share and transferring whatever file you wanted, you would expect the file to appear on nextcloud itself. However, that’s not the case. There are extra steps to perform.

  1. Ensure nextcloud has the permissions to read your file. Using ls -la, check on the other nextcloud files to identify the owner. If you are like me and using the nextcloud AIO docker image, the owner is likely the user www-data

  2. Change owner using the chown command
    1
    
    chown -R www-data /folder/to/change
    
  3. Using docker ps, identity the container running nextcloud. Similarly, if you are using the nextcloud AIO docker image, the container running nextcloud is named: nextcloud-aio-nextcloud

  4. Using docker exec, enter into the container’s shell
    1
    
    docker exec -it nextcloud-aio-nextcloud /bin/bash
    
  5. Run the following command to rescan all files
    1
    
    sudo -u www-data -E php occ files:scan --all
    

The file will now appear in your nextcloud instance!

Cleanup

For security purposes, you might want to deactivate the “Allow non-root mount” option from Problem 1: Mounting NFS share on Windows.

This post is licensed under CC BY 4.0 by the author.

Trending Tags