ftp causing invalid syntax

But wouldn't the pictures be written to the pi/home folder first anyway, or have I missed something.

If I use a USB thumb drive, how do I tell the python script to store or write the pictures on the said drive.

Reply to
RobH
Loading thread data ...

Thanks for the above but when I use import ftplib, it returns bash: import: command not found.

Reply to
RobH

You ran the script with Bash instead of Python, then.

Perhaps this would go more smoothly if you learned some Python?

--
https://www.greenend.org.uk/rjk/
Reply to
Richard Kettlewell

I found the said line or information here:

formatting link

And I used the 2nd line first, then both lines, and still it returned the same error message: invalid syntax.

In answer to the b) the ip address of the NAS server means I actually use an ip address to access my NAS server, 192.168.x.x as an example. There would not be any added spaces when it is used.

When you say: Just create your filename with the full path to the NAS mount point/directory you want to use for saving videos.

Do you then mean to use an exact file name to move or upload to the NAS mount point. This would be impractical I think because each picture has a date in the name, ie: 2018-05-07_22.40.54.jpg

Reply to
RobH

I'm sorry but you have lost me with the above statements

Reply to
RobH

ok, but where would I do that in the python script which takes the picures.

Reply to
RobH

The main problem I have is that ftp returns an invalid syntax.

If there some other way of uploading the pictures automatically , I would certainly try it.

Reply to
RobH

Thanks but that fails at the first line.

import os, subprocess returns bash: import: command not found.

Reply to
RobH

When I run the script in a terminal window it fails there with invalid syntax at the ftp:// part

Reply to
RobH

Who , me, I have tried what other posters have suggested and it does not work.

Reply to
RobH

Do you mean I should add a fileshare to the NAS in the /etc/fstab window. This lists all of my drives and I don't want to screw it up

I've added a Unix share for the PI Zero on one of the drives.

Reply to
RobH

Are you using os.system or pycurl or ftplib yet?

Reply to
mm0fmf

On Tue, 15 May 2018 20:35:09 +0100, RobH declaimed the following:

Read the paragraph above those lines "To run an automated process in Linux you need a shell script"... Shell scripts are run in the command line, they are NOT Python scripts (you /start/ Python from a command line, but then /it/ runs the Python script).

You really need to look at a few introductions to Linux, BASH (shell), and Python, because the impression you are presenting is that of someone who thinks all of them work at the same level. Especially with the other post where you were entering import ftplib at a shell prompt, when /that/ is a Python statement.

Show us an example of the command you would use to create or open a file on that NAS... Normally, in Linux, the IP or hostname would appear in the mount command, or in an fstab entry, and the mounted path would not use the IP/hostname itself (this allows the IP/hostname to change in the future while the mount point stays the same, and programs are not affected). .

And here again you are specifying a still-image JPEG, but your Python script is making an H264 video... Different type of file, different extension.

What difference does the file name make? You generated the name, you can reuse the name in multiple statements.

{Obviously untested -- I don't have a picamera, and I don't have a NAS} {Save as "CameraExample.py", run by enterings "python CameraExample.py" at the command line} {Watch out for line wrap on long comments; and don't mess up the indentation}

-=-=-=-=- from picamera import PiCamera import time import os import os.path import shutil

from gpiozero import MotionSensor #According to Google MotionSensor is in gpiozero

pir = MotionSensor(4)

camera = PiCamera()

while True: pir.wait_for_motion() triggerTime = time.time()

#create base file name at time of motion trigger fname = time.strftime("%Y-%m-%d_%H.%M.%S.h264", time.localtime(triggerTime)) RAMname = os.path.join("/run/shm", fname) NASname = os.path.join("/path/to/NAS/mount/point", fname) camera.start_preview()

#capture video to RAM device first camera.start_recording(RAMname) camera.wait_recording(10) camera.stop_recording() camera.stop_preview()

#copy from RAM device to NAS device shutil.copyfile(RAMname, NASname)

#delete file from RAM device os.unlink(RAMname) #os.remove() is same function

#set up next check time time.sleep((triggerTime + 30.0) - time.time())

-=-=-=-=-

Obviously you'll have to replace "/path/to/NAS/mount/point" with the correct specification for your system. A proper NAS should appear as just part of the file system -- no use of FTP or other fancy protocols should be needed to access it.

--
	Wulfraed                 Dennis Lee Bieber         AF6VN 
	wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/
Reply to
Dennis Lee Bieber

Thanks for the above code, and when I run it , it returns this, when movement is detected,:

Traceback (most recent call last) File "intruder_recmotion.py", line 37, in shutil.copyfile(RAMname, NASname) File "/usr/lib/python 2.7/shutil.py", line 83, in copyfile with open(dst, 'wb') as fdst: IOError: [Errno 2] No such file or directory: '/192.168.0.22/mnt/CCTV/PiZero/2018-16-16_11.25.36.h264'

I have checked the path to the PiZero folder or dataset on my FreeNAS box and it is correct.

Thanks again

Reply to
RobH

I mean that the NAS likely PUBLISHES a fileshare. On the PI, you should mount that fileshare That will make the python program to think it writes on a local drive, when in fact you write on the NAS - without ftp.

so if your python program writes to /mnt/share/file.jpg the file ends up on the NAS, given the example above

you can mount it in /etc/fstab if you want, or mount by hand as described above

--
--
Reply to
Björn Lundin

do you REALLY have a local directory called 192.168.0.22 ??

you should MOUNT the NAS (which may be at 192.168.0.22) on a local directory.

as I said before #mount -t cifs -o username=USERNAME,password=PASSWD //192.168.1.88/shares /mnt/share

on one line. as root or sudo

like #mount -t cifs -o username=USERNAME,password=PASSWD //192.168.0.22/shares/ /mnt/nas

and save the file to '/mnt/nas/2018-16-16_11.25.36.h264'

--
--
Reply to
Björn Lundin

On Wed, 16 May 2018 11:43:41 +0100, RobH declaimed the following:

On the R-PI, show us the result of

ls -a /

{The following is a Debian install in a VirtualBox instance, not an actual R-PI}

wulfraed@stretch:~$ ls -a / . dev initrd.img.old libx32 opt sbin usr .. etc lib lost+found proc srv var bin home lib32 media root sys vmlinuz boot initrd.img lib64 mnt run tmp vmlinuz.old wulfraed@stretch:~$

According to the error message, you are looking to have a directory named 192.168.0.22 in the root of your R-PI filesystem.

Or (given your phrasing) you've actually mounted the R-PI on the NAS, and not the NAS on the R-PI. Whatever the path is, it has to be valid ON THE R-PI -- logging into the NAS via some administration interface doesn't validate anything other than that you created subdirectories on it.

formatting link

--
	Wulfraed                 Dennis Lee Bieber         AF6VN 
	wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/
Reply to
Dennis Lee Bieber

No, that is the IP address of path or part of it anyway

Where on what device, on the Pi Zero or on my NAS server

As a separate file on the Pi Zero??

Reply to
RobH

ls -a / . bin dev home lost+found media opt root sbin sys usr .. boot etc lib man mnt proc run srv tmp var

Reply to
RobH

That is the reason the error message say that it does not find the directory. look again. the first part od the file

^^^^^^^^^^^^^

So as I said:

mount (in this context) means 'bringing the filesystem of the NAS looking like a part od the filesystem of the PI

So again : on the PI do

here I guess I need to clarify that you should exchange * USERNAME to the username used to log on to the NAS * PASSWORD to the password of above user on the NAS * //192.168.1.88/shares to the ipaddres of the NAS + the name of the share * /mnt/share to a local directory. /mnt/nas is not to bad

if /mnt/nas does not exist - create it : sudo mkdir /mnt/nas sudo chown -R pi:pi /mnt/nas

to fix permissions

Now - after this manouver you have linked the Pi's /mnt/nas with the NAS's /shares directory

whatever you write - on the PI - to /mnt/nas end up on the NAS. NOT on the PI. which is the whole point

no - as above - it will save it on the NAS. NOT on the PI since the mount command links the filesystem with each other.

(and as a comment to other error you had with bash error messages) make bash run python which run the python file.

like

$python3 your_python_file.py

--
--
Reply to
Björn Lundin

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.