Bosse_B
Posts: 981
Joined: Thu Jan 30, 2014 9:53 am

Using wget targeting a NAS unit?

Fri Aug 01, 2014 8:30 am

I have two Pi:s running on my home network:
1) RASPBMC with XBMC, uses my Synology NAS as source of videos. Hooked to my Sony TV.
2) RASPBIAN currently used only for VPN connectivity to my network (OpenVPN and PPTP servers running). Headless.

Now I would like to know if I can download files via the second (RASPBIAN) Pi using wget and targeting the file share on the Synology NAS?
The file I need is a little less than 1 GB and it might not fit on the Pi SDCard so I hoped that somehow I could set it up such that the file is directly written on the NAS.
But I am rather "dummy" concerning Linux and particularly in embedded devices like the Pi.

Note:
I am located about 100 km from my home network and my only access to the Pi units is by way of VPN into the network using the second Pi and then opening a command shell using PuTTY on my Windows laptop.
So in doing what I need to do to accomplish the task I would like instructions on how to do it from the command line of the Pi.
I do have a GUI access to the Synology NAS Disk-manager so if there is something that needs setting up on that end I can do it also remotely.

If I can mount a NAS share on the Pi as a disk drive (how do i do that?) and then make a cd to that drive will then a simple wget <url> download the file to the current dir, i.e. on the NAS?
Or is it a more complex command I need?
Bo Berglund
Sweden

User avatar
RaTTuS
Posts: 10559
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Using wget targeting a NAS unit?

Fri Aug 01, 2014 8:39 am

if the raspbmc machine can see the network
you can possibly
ssh into that machine from the rasbian one
and
wget direct from there

I'm not sure if wget can push to a remote location but
http://www.gnu.org/software/wget/manual/wget.html
may help
there are other ways also
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Using wget targeting a NAS unit?

Fri Aug 01, 2014 8:51 am

Check if your NAS supports NFS or SaMBa/CIFS
( a.k.a. Windows File Sharing).

Then mount your NAS into your directory tree on Raspbian.

https://access.redhat.com/documentation ... mount.html

http://www.cyberciti.biz/faq/linux-moun ... ows-share/

wget can now write to your mountpoint like it is the SD-Card.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

Bosse_B
Posts: 981
Joined: Thu Jan 30, 2014 9:53 am

Re: Using wget targeting a NAS unit?

Fri Aug 01, 2014 11:02 am

Thanks,
the Synology NAS exports a couple of directories using Samba (Windows sharing) so on my Windows machines I just go to \\NAS\data\somedir and "it just works".
I would ideally like to be able to access this from the Pi as well (R/W).
When reading the second link I was a bit confused so I will post here my interpretation of the command sequence to download the file all via PuTTY to the RASPBIAN Pi.
So after logging in as pi to the raspberry pi using PuTTY I am on a command prompt and I type the lines below, right?
(My NAS is on the IP address shown):

Code: Select all

# mount.cifs //192.168.0.138/data /mnt/cifs -o
username=<my login name>,password=<my password>,domain=<workgroup name>
cd /mnt/cifs/video
wget <url to file on Internet>
Is this correct?
I have some questions:
1) The first line starts with a # char, is this not a comment in most cases? Do i have to enter that?
2) Why use /mnt/cifs? Is there some magic concerning the cifs name that makes it required?
3) How does the workgroup name come into play?

Excuse my ignorance, I have just used cook-book descriptions to set up my two Pi units to work (and they do!).
Bo Berglund
Sweden

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Using wget targeting a NAS unit?

Fri Aug 01, 2014 12:02 pm

1) The octothorphe simply states that anything after it has to
be entered at the root shell (in this case , mounting needs
root privileges)

2) The mountpoint is arbitary , but consider following :
a) It should be an already existing folder.
b) If you need to create it, you propably need root privileges.

3) I'm not sure if you need to supply a domain. If it doesn't work
without one , i would try using "WORKGROUP" the second time.

To execute a single command with root privileges , prepend
it with "sudo". To start a session with root privileges
(a "root shell") , use "sudo -s". Observe how the command
prompt changes. Use "exit" to drop back to the
unprivileged (as user "pi" by default) session .

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

Bosse_B
Posts: 981
Joined: Thu Jan 30, 2014 9:53 am

Re: Using wget targeting a NAS unit?

Fri Aug 01, 2014 7:52 pm

I had already tried to follow the link about CIFS mounting,
But this is what happened (I have replaced sensitive info with ****):

Code: Select all

pi@raspbian-pi ~ $ mount.cifs //192.168.0.138/data/bosse /mnt/cifs -o username=user,password=*****,domain=*****
Couldn't chdir to /mnt/cifs: No such file or directory
pi@raspbian-pi ~ $ mkdir /mnt/cifs
mkdir: cannot create directory `/mnt/cifs': Permission denied
pi@raspbian-pi ~ $ sudo mkdir /mnt/cifs
pi@raspbian-pi ~ $ mount.cifs //192.168.0.138/data/user /mnt/cifs -o username=user,password=*****,domain=*****
mount.cifs: permission denied: no match for /mnt/cifs found in /etc/fstab
pi@raspbian-pi ~ $
Now I see that you state that one needs to be root to do a mount, so I added sudo in front:

Code: Select all

$ sudo mount.cifs //192.168.0.138/data/bosse /mnt/cifs -o username=*****,password=*******,domain=******
$ ls -l /mnt/cifs
total 8935
-rwxrwxrwx 1 1026 users  286719 Mar 21  2012 Android Sms New_1.mp3
.... more files....
So the sudo thing worked!
Then I tried wget to get the file I need:

Code: Select all

$ cd /mnt/cifs
$ wget http://companydomain/somepath/2014(CI)/21.2.4.4/thefile
-bash: syntax error near unexpected token `('
So it seems like they have placed the file i need in an URL containing ( and ) and this seems to be a problem for wget.
Is there any way around it?
On my Win7 laptop I can use the URL and get the file, but it is not then on the right place (I am remote).
Bo Berglund
Sweden

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Using wget targeting a NAS unit?

Sat Aug 02, 2014 7:49 am

Try putting the URL in quotes :

Code: Select all

$ wget "http://companydomain/somepath/2014(CI)/21.2.4.4/thefile"
ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

Bosse_B
Posts: 981
Joined: Thu Jan 30, 2014 9:53 am

Re: Using wget targeting a NAS unit?

Sat Aug 02, 2014 8:08 am

I do not think that will work, but what actually did work was to escape the offending characters with \ like so:

Code: Select all

$ wget http://companydomain/somepath/2014\(CI\)/21.2.4.4/thefile
However, I did not have success this time either even though wget got a bit further.
It seems like my mount of the NAS share is not working well. It sets the file permissions of new files as -rw-r--r-- rather than -rwxrwxrwx as it should.
For some reason wget is able to initially create the target file, but as soon as it wants to start filling it with downloaded data there is a permission denied error.
Likewise if I enter the command "touch somefile" where somefile is not existing previously, then I get a permission error too.
But when I examine the files (ls -l) I see that the somefile file has been created and has a timestamp of now, but length is zero and it has permissions -rw-r--r-- and so cannot be used.

Notice that I have modified the mount command to include option rw (for read/write access) but it does not help since the files themselves become -rw-r--r--
Bo Berglund
Sweden

User avatar
DougieLawson
Posts: 39126
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Using wget targeting a NAS unit?

Sat Aug 02, 2014 8:17 am

Try using

Code: Select all

wget http://companydomain/somepath/2014%28CI%29/21.2.4.4/thefile
http://www.vermontdatabase.com/cloudwri ... coding.htm
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
emgi
Posts: 357
Joined: Thu Nov 07, 2013 4:08 pm
Location: NL

Re: Using wget targeting a NAS unit?

Sat Aug 02, 2014 9:30 am

I have been pretty successful with the following mount procedure:

Code: Select all

emgi@raspberrypi:~$ sudo su
root@raspberrypi:/home/emgi# cd
root@raspberrypi:~# mkdir /nas46
root@raspberrypi:~# vi /etc/hosts
root@raspberrypi:~# mount //nas46/share /nas46
Password:
root@raspberrypi:~#
In /etc/hosts I simply add a line with the ip address of the NAS. This is an essential step because the Pi needs to be able to 'resolve' the hostname.
This is the resulting output of mount:

Code: Select all

root@raspberrypi:~# mount
/dev/root on / type ext4 (rw,noatime,data=ordered)
devtmpfs on /dev type devtmpfs (rw,relatime,size=219832k,nr_inodes=54958,mode=755)
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=44800k,mode=755)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /run/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=89580k)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620)
/dev/mmcblk0p1 on /boot type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro)
//nas46/share on /nas46 type cifs (rw,relatime,vers=1.0,cache=strict,username=root,domain=NAS46,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.202.224,file_mode=0755,dir_mode=0755,nounix,serverino,rsize=61440,wsize=65536,actimeo=1)
root@raspberrypi:~#
This procedure has been tested on other linux distro's and with more than one brand of NAS.
For the sake of demonstration I just repeated it once more on my new B+ and the output is what you see here.

/emgi

Bosse_B
Posts: 981
Joined: Thu Jan 30, 2014 9:53 am

Re: Using wget targeting a NAS unit?

Sat Aug 02, 2014 12:42 pm

Did not work. Same permission problem.
Note:
My NAS does not have the guest account enabled, only authenticated users are allowed access.

But the user registration I thought was taken care of with the original command by entering the credentials on the command line:

Code: Select all

mount.cifs //nas/data/user /mnt/cifs -o username=user,password=*****,domain=*****,rw
Note the extra option rw, it should mount the share read/write but it seems also not to work.
Bo Berglund
Sweden

User avatar
emgi
Posts: 357
Joined: Thu Nov 07, 2013 4:08 pm
Location: NL

Re: Using wget targeting a NAS unit?

Sat Aug 02, 2014 12:55 pm

Yep, but not all my shares are open either.
To mount my personal folder, I can do the same thing by specifying the -o username=userid as an option to the mount command. I leave out the password and then I'm prompted for it.
So even if you are using protected shares, this option should still work.
Use forward slashes and make sure the device name matches the entry in /etc/hosts.
Please note that I'm using workgroup security. If you have the NAS as part of a Windows domain or AD then it will not work.

User avatar
DougieLawson
Posts: 39126
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Using wget targeting a NAS unit?

Sat Aug 02, 2014 1:09 pm

emgi wrote: I leave out the password and then I'm prompted for it.
Why not use a credentials file? You store userid/password in that (and restrict it with ownership and permission bits) and pass that as an option in /etc/fstab or on an smbmount command. https://www.samba.org/samba/docs/man/ma ... ifs.8.html
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
emgi
Posts: 357
Joined: Thu Nov 07, 2013 4:08 pm
Location: NL

Re: Using wget targeting a NAS unit?

Sat Aug 02, 2014 1:39 pm

DougieLawson wrote:
emgi wrote: I leave out the password and then I'm prompted for it.
Why not use a credentials file? You store userid/password in that (and restrict it with ownership and permission bits) and pass that as an option in /etc/fstab or on an smbmount command. https://www.samba.org/samba/docs/man/ma ... ifs.8.html
Well, actually I don't want it to automount for security reasons.
The server in casu is my webserver and I don't want it to have a permanent connection to personal information, just in case. :|
When accessing this share I perform the mount, get/put whatever file(s) needed and dismount again.

/emgi

Bosse_B
Posts: 981
Joined: Thu Jan 30, 2014 9:53 am

Re: Using wget targeting a NAS unit?

Sat Aug 02, 2014 2:52 pm

It seems like my attempts work partially, after all I CAN list the files and presumably also read them.
It is just that all access for me is read only.
No, wait!
All existing files in the share are -rwxrwxrwx and I can access them just fine. So I must be logged on fine, really.

But whatever file I want to create myself, like using touch on a new name wind up as -rw-r--r-- and are then unusable for further work.
Bo Berglund
Sweden

User avatar
DougieLawson
Posts: 39126
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Using wget targeting a NAS unit?

Sat Aug 02, 2014 3:12 pm

What UMASK value are you getting on your CIFS/Samba mount? If you want -rwxrwxrwx you'll need UMASK=0000.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Bosse_B
Posts: 981
Joined: Thu Jan 30, 2014 9:53 am

Re: Using wget targeting a NAS unit?

Sat Aug 02, 2014 6:02 pm

What is the command to retrieve the UMASK value?
I tried as follows:

Code: Select all

pi@raspbian-pi ~ $ UMASK
-bash: UMASK: command not found
As you can see there is no reaction....
Bo Berglund
Sweden

User avatar
DougieLawson
Posts: 39126
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Using wget targeting a NAS unit?

Sun Aug 03, 2014 11:01 am

man mount.cifs
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Bosse_B
Posts: 981
Joined: Thu Jan 30, 2014 9:53 am

Re: Using wget targeting a NAS unit?

Sun Aug 03, 2014 12:09 pm

Thanks, but this is gooblediboo for me....
Scrolling down a ton of options I do not understand I get to this, which does not tell me what I need to do in a way that makes me able to do it...
FILE AND DIRECTORY OWNERSHIP AND PERMISSIONS
The core CIFS protocol does not provide unix ownership information or mode for files and directories. Because of
this, files and directories will generally appear to be owned by whatever values the uid= or gid= options are set,
and will have permissions set to the default file_mode and dir_mode for the mount. Attempting to change these
values via chmod/chown will return success but have no effect.

When the client and server negotiate unix extensions, files and directories will be assigned the uid, gid, and mode
provided by the server. Because CIFS mounts are generally single-user, and the same credentials are used no matter
what user accesses the mount, newly created files and directories will generally be given ownership corresponding
to whatever credentials were used to mount the share.

If the uid´s and gid´s being used do not match on the client and server, the forceuid and forcegid options may be
helpful. Note however, that there is no corresponding option to override the mode. Permissions assigned to a file
when forceuid or forcegid are in effect may not reflect the the real permissions.

When unix extensions are not negotiated, it´s also possible to emulate them locally on the server using the
"dynperm" mount option. When this mount option is in effect, newly created files and directories will receive what
appear to be proper permissions. These permissions are not stored on the server however and can disappear at any
time in the future (subject to the whims of the kernel flushing out the inode cache). In general, this mount option
is discouraged.

It´s also possible to override permission checking on the client altogether via the noperm option. Server-side
permission checks cannot be overriden. The permission checks done by the server will always correspond to the
credentials used to mount the share, and not necessarily to the user who is accessing the share.
Probably I need to add something to my mount command line in order to make the files created on the NAS being accessible to the owner (=me) as well as all others (-rwxrwxrwx).
But what?

Code: Select all

sudo mount.cifs //nas/data/bosse /mnt/cifs -o username=****,password=*****,domain=****,rw
Bo Berglund
Sweden

User avatar
emgi
Posts: 357
Joined: Thu Nov 07, 2013 4:08 pm
Location: NL

Re: Using wget targeting a NAS unit?

Sun Aug 03, 2014 12:20 pm

Please check the output of the mount command I posted earlier.
I believe you could try to include : file_mode=0755,dir_mode=0755 (or use 0777 if you like)
For me this is working so first step could be to get the same settings on your device.

When the mount itself was successful then you can post the output so that we can have a look.

/emgi

Bosse_B
Posts: 981
Joined: Thu Jan 30, 2014 9:53 am

Re: Using wget targeting a NAS unit?

Sun Aug 03, 2014 1:13 pm

Code: Select all

pi@raspbian-pi ~ $  sudo mount.cifs //nas/data/bosse /mnt/cifs -o username=****,password=*****,domain=*****,rw,file_mode=0755,dir_mode=0755
pi@raspbian-pi ~ $ cd /mnt/cifs
pi@raspbian-pi /mnt/cifs $ touch korvkiosk2
touch: cannot touch `korvkiosk2': Permission denied
pi@raspbian-pi /mnt/cifs $ ls -l k*
-rw-r--r-- 1 1026 users 0 Aug  2 00:26 kallekula
-rw-r--r-- 1 1026 users 0 Aug  3 15:08 korvkiosk2
Seemed like it did not work...
What about /mnt/cifs?
Is there something in the directory that will host the share that is wrong?
I seem to have read that the directory must have some properties, only I don't know which and also I don't know how to set them.

Code: Select all

pi@raspbian-pi ~ $ ls -l /mnt
total 0
drwxrwxrwx 7 1026 users 0 Aug  3 15:08 cifs
????
Bo Berglund
Sweden

User avatar
emgi
Posts: 357
Joined: Thu Nov 07, 2013 4:08 pm
Location: NL

Re: Using wget targeting a NAS unit?

Sun Aug 03, 2014 1:38 pm

You are still using the domain option. For workgroup security, this parameter is not needed.
Please try to mount without it. (only username, password)
Do you have the NAS set up as part of a Windows domain?
Then I would suggest you take it out because that will definitely affect your permissions.

Bosse_B
Posts: 981
Joined: Thu Jan 30, 2014 9:53 am

Re: Using wget targeting a NAS unit?

Sun Aug 03, 2014 2:00 pm

Code: Select all

pi@raspbian-pi ~ $ sudo umount /mnt/cifs
pi@raspbian-pi ~ $ sudo mount.cifs //nas/data/bosse /mnt/cifs -o username=****,password=*****,rw,file_mode=0755,dir_mode=0755
pi@raspbian-pi ~ $ cd /mnt/cifs
pi@raspbian-pi /mnt/cifs $ ls -l
total 8935
-rwxrwxrwx 1 1026 users  286719 Mar 21  2012 Android Sms New_1.mp3
...
-rw-r--r-- 1 1026 users       0 Aug  2 00:26 kallekula
-rw-r--r-- 1 1026 users       0 Aug  3 15:08 korvkiosk2
...
pi@raspbian-pi /mnt/cifs $ touch korvkiosk3
touch: cannot touch `korvkiosk3': Permission denied
pi@raspbian-pi /mnt/cifs $ ls -l k*
-rw-r--r-- 1 1026 users 0 Aug  3 15:56 korvkiosk3
What did I do wrong this time? Same non-working permissions on the created file.
Took out the domain == workgroup name. It is NOT connected to a Windows domain but the NAS uses the same namd (different from 'WORKGROUP').
Bo Berglund
Sweden

User avatar
emgi
Posts: 357
Joined: Thu Nov 07, 2013 4:08 pm
Location: NL

Re: Using wget targeting a NAS unit?

Sun Aug 03, 2014 4:18 pm

Interestingly, the NAS (or the Pi?) does not recogize the username so it lists the userID instead.
Just one line to show my point:

Code: Select all

...
-rw-r--r-- 1 1026 users       0 Aug  2 00:26 kallekula
If the user was recognized, its permissions would be inherited and your problem might be solved.
This is a noticable difference with how I do it because on my environment, the user exists, both on the Pi and on the NAS.
Also, it looks like you are using the default user-id (pi) to create the files. I can see this from the prompt.
So to begin with, you should create a user named 'pi' on the NAS with appropriate privileges like being member of the group named 'users'. Alternatively you can create a new user on the Pi which already exists on the NAS.
No need to say that in both cases, the password should also match.

Bosse_B
Posts: 981
Joined: Thu Jan 30, 2014 9:53 am

Re: Using wget targeting a NAS unit?

Sun Aug 03, 2014 7:32 pm

I visited my son-in-law today and together we solved the problem...
This is the working mount command we were able to use:

Code: Select all

sudo mount.cifs //nas/data/bosse /mnt/cifs -o username=****,password=****,rw,file_mode=0777,dir_mode=0777,noperm
noperm means that the client (the Pi does not check or impose permissions, instead this is done on the server. And now it works!
:D
Bo Berglund
Sweden

Return to “Advanced users”