JohnnyCyp
Posts: 75
Joined: Sun Mar 31, 2019 11:05 pm

error_perm: 553 Can't open that file: Permission denied

Fri May 24, 2019 12:21 pm

Hello, how i solve this error ?
error_perm: 553 Can't open that file: Permission denied


Traceback (most recent call last):
File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "/home/pi/Project/functions.py", line 248, in ftpSession
ftp.storbinary('STOR ' + image_name, file) # send the file
File "/usr/lib/python2.7/ftplib.py", line 471, in storbinary
conn = self.transfercmd(cmd, rest)
File "/usr/lib/python2.7/ftplib.py", line 376, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "/usr/lib/python2.7/ftplib.py", line 339, in ntransfercmd
resp = self.sendcmd(cmd)
File "/usr/lib/python2.7/ftplib.py", line 249, in sendcmd
return self.getresp()
File "/usr/lib/python2.7/ftplib.py", line 224, in getresp
raise error_perm, resp
error_perm: 553 Can't open that file: Permission denied

Code: Select all

def ftpSession(self, q, image_path, image_name):
      while True:
        try:
          urlopen('https://www.google.com')
          break
        except:
          print ('No active internet connection in order to upload the picture. Retry in 30 sec FTP')
        time.sleep(30)
      session = ftplib.FTP('ipRPi','username','pass') # Here you need to provide your ftp Host, Username and password
      session.cwd('image folder')                         #Give the correct folder where to store the image
      print ("FTP Connection established")
      file = open(image_path, 'rb')                  # file to send
      session.storbinary('STOR ' + image_name, file)     # send the file
      file.close()                                    # close file and FTP
      session.quit()
      link = 'ftp://ipRPi/imagefolder' + image_name # This line here generates a link of the uploaded picture based on your webserver
      print ("File has been uploaded!")
      return link
Last edited by JohnnyCyp on Fri May 24, 2019 12:49 pm, edited 1 time in total.

Andyroo
Posts: 3324
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: error_perm: 553 Can't open that file: Permission denied

Fri May 24, 2019 12:30 pm

Is this the correct code snippet as you had an error on the ‘shell=True...’ statement earlier?

Can you say what line this refers to? It could be the ftp site not having the correct permission or a log file?

A bit of background as to where the code came from and what you are trying to do would help folk to help you...
Need Pi spray - these things are breeding in my house...

User avatar
topguy
Posts: 5569
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: error_perm: 553 Can't open that file: Permission denied

Fri May 24, 2019 12:32 pm

Have you tried to send the file with FTP manually ?

Code: Select all

session.storbinary('STOR ' + image_name, file)
The values of "image_name" and "file" are not visible to us so we cant say if their values are relevant to the error.
But either you dont have access to the local "file" or you dont have write access to whereever "image_name" is pointing.

JohnnyCyp
Posts: 75
Joined: Sun Mar 31, 2019 11:05 pm

Re: error_perm: 553 Can't open that file: Permission denied

Fri May 24, 2019 12:44 pm

Andyroo wrote:
Fri May 24, 2019 12:30 pm
Is this the correct code snippet as you had an error on the ‘shell=True...’ statement earlier?

Can you say what line this refers to? It could be the ftp site not having the correct permission or a log file?

A bit of background as to where the code came from and what you are trying to do would help folk to help you...
Yes i had before a syntax error with the shell=True(image_path,'rb') and i changed it to file = open(image_path, 'rb'). and it looks like i forgot to change it here in the forum because i have copy-paste it from the another thread.

My program is to take picture with pi camera when PIR sensor detected a motion and the picture will be store to ftp server and then it will take the picture from ftp server and send to email.
When the error happens i received an mail to my email but without a picture.

JohnnyCyp
Posts: 75
Joined: Sun Mar 31, 2019 11:05 pm

Re: error_perm: 553 Can't open that file: Permission denied

Fri May 24, 2019 12:57 pm

topguy wrote:
Fri May 24, 2019 12:32 pm
Have you tried to send the file with FTP manually ?

Code: Select all

session.storbinary('STOR ' + image_name, file)
The values of "image_name" and "file" are not visible to us so we cant say if their values are relevant to the error.
But either you dont have access to the local "file" or you dont have write access to whereever "image_name" is pointing.
file = open(image_path, 'rb')
image_path point to the directory of images files when i store to ftp
image_name = todays_date.strftime('%m-%d-%y-%H%M') + '.jpg'
image_name is pointing to the images name files with date and time.
What is the right way to give permission access to a file or folder ? I have used the FileZilla but the error still remains...

Image

User avatar
Paeryn
Posts: 2564
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: error_perm: 553 Can't open that file: Permission denied

Fri May 24, 2019 2:43 pm

From the error message that is coming from the remote FTP server telling you that your connection doesn't have permission to create the file.

Looking at the code sample you gave, did you use the correct directory name? In your cwd() you use the name 'image folder' but later on refer to the link as being in 'imagefolder' (note the space in the cwd() which isn't in the link)

Code: Select all

      session.cwd('image folder')
...
      link = 'ftp://ipRPi/imagefolder' + image_name
She who travels light — forgot something.

JohnnyCyp
Posts: 75
Joined: Sun Mar 31, 2019 11:05 pm

Re: error_perm: 553 Can't open that file: Permission denied

Fri May 24, 2019 3:05 pm

Paeryn wrote:
Fri May 24, 2019 2:43 pm
From the error message that is coming from the remote FTP server telling you that your connection doesn't have permission to create the file.

Looking at the code sample you gave, did you use the correct directory name? In your cwd() you use the name 'image folder' but later on refer to the link as being in 'imagefolder' (note the space in the cwd() which isn't in the link)

Code: Select all

      session.cwd('image folder')
...
      link = 'ftp://ipRPi/imagefolder' + image_name
I wrote an example of my code in hurry... here is the my full code:

Code: Select all

def ftpSession(self, q, image_path, image_name):
      while True:
        try:
          urlopen('https://www.google.com')
          break
        except:
          print ('No active internet connection in order to upload the picture. Retry in 30 sec FTP')
        time.sleep(30)
      ftp = FTP('192.168.1.121')                     # ftp Host (IP of RPi)
      ftp.login('pi','HomeSecurity93')               # ftp username and password of RPi
      ftp.cwd('home/pi/Project/pics/')          # folder where to store the image
      print ("FTP Connection established")
      file = open(image_path, 'rb')                  # file to send
      ftp.storbinary('STOR ' + image_name, file)     # send the file
      file.close()                                   # close file and FTP
      ftp.quit()
      link = 'http://192.168.1.121:5000/home/pi/Project/pics/' + image_name # This line here generates a link of the uploaded picture based on your webserver
      print ("File has been uploaded!")
      return link

#Sends email using the google's SMTP Server.
    def sendEmail(self, q, Subject, textBody, attachment, receiver):
      """This method sends an email"""
      EMAIL_SUBJECT = Subject
      EMAIL_USERNAME = ''
      EMAIL_FROM = 'HomeSecurity'
      EMAIL_RECEIVER = receiver
      #EMAIL_FROM = ''
      #EMAIL_RECEIVER = ''
      GMAIL_SMTP = "smtp.gmail.com"
      GMAIL_SMTP_PORT = 587
      GMAIL_PASS = '' # And your email password
      TEXT_SUBTYPE = "plain"

      #Create the email.
      msg = MIMEMultipart()
      msg["Subject"] = EMAIL_SUBJECT
      msg["From"] = EMAIL_FROM
      msg["To"] = EMAIL_RECEIVER
      body = MIMEMultipart('alternative')
      body.attach(MIMEText(textBody, TEXT_SUBTYPE ))
      #Attach the message
      msg.attach(body)
      #Attach a picuture.
      if attachment != "NO":
        msg.attach(MIMEImage(file(attachment).read()))

      while True:
        try:
          urlopen('https://www.google.com')
          break
        except:
          print ('No active internet connection in order to send the e-Mail. Retry in 30 sec')
        time.sleep(30) 
      print ("Connection to e-Mail server established")
      try:
        smtpObj = SMTP(GMAIL_SMTP, GMAIL_SMTP_PORT)
        #Identify yourself to GMAIL ESMTP server.
        smtpObj.ehlo()
        #Put SMTP connection in TLS mode and call ehlo again.
        smtpObj.starttls()
        smtpObj.ehlo()
        #Login to service
        smtpObj.login(user=EMAIL_USERNAME, password=GMAIL_PASS)
        #Send email
        smtpObj.sendmail(EMAIL_FROM, EMAIL_RECEIVER, msg.as_string())
        #close connection and session.
        smtpObj.quit()
        print ('e-Mail has been sent!')
      except SMTPException as error:
        print ("Error: unable to send email :  {err}".format(err=error))

#Capture image using the Pi Camera.
    def capture_image(self):
      grab_cam = subprocess.Popen("sudo fswebcam -r 1920x1080 --timestamp '%d-%m-%Y %H:%M:%S (%Z)'   -q /home/pi/Project/pics/%m-%d-%y-%H%M.jpg", shell=True)
      grab_cam.wait()
      todays_date = dt.datetime.today()
      image_name = todays_date.strftime('%m-%d-%y-%H%M') + '.jpg'
      return image_name

#Calls the required functions to upload the captured image on the server, 
#send email and SMS to the user, to alert about the intrudion
    def takePicture(self, image_name):
      image_path = '/home/pi/Project/pics/' + image_name
      #interact().ftpSession(image_path, image_name)
      Process(target=interact().ftpSession, args=(queue, image_path, image_name)).start()
      rLink = 'http://192.168.1.121:5000/home/pi/Project/pics/' + image_name
      #interact().sendEmail("Intruder Detected", "Here is your intruder:", image_path, database().getEmail()) #Dynamic get receiver
      Process(target=interact().sendEmail, args=(queue, "Intruder Detected", "Here is your intruder:", image_path, database().getEmail())).start()
      print (rLink)
      #interact().sendSms("Here is your intruder: " + rLink)
      Process(target=interact().sendSms, args=(queue, "Here is your intruder: + rLink")).start()
also i make some changes and the error is little different now...

Motion detected, armed status: True
Correct passcode not entered, emailing picture and sounding alarm.
http://192.168.1.121:5000/home/pi/Proje ... 9-1800.jpg
'30'
Attempt to send SMS ...
Connection to TXTLocal established
SMS has been sent!
Process Process-2:1:
Traceback (most recent call last):
File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "/home/pi/Project/functions.py", line 245, in ftpSession
ftp.cwd('home/pi/Project/pics/') # folder where to store the image
File "/usr/lib/python2.7/ftplib.py", line 562, in cwd
return self.voidcmd(cmd)
File "/usr/lib/python2.7/ftplib.py", line 254, in voidcmd
return self.voidresp()
File "/usr/lib/python2.7/ftplib.py", line 229, in voidresp
resp = self.getresp()
File "/usr/lib/python2.7/ftplib.py", line 224, in getresp
raise error_perm, resp
error_perm: 550 Can't change directory to home/pi/Project/pics/: No such file or directory
Last edited by JohnnyCyp on Sat May 25, 2019 12:30 pm, edited 1 time in total.

Andyroo
Posts: 3324
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: error_perm: 553 Can't open that file: Permission denied

Fri May 24, 2019 3:25 pm

The last line maybe the clue
home/pi/Project/pics/
That’s a relative directory to your current one.

Maybe it should be /home/pi/Project/pics/ ?
Need Pi spray - these things are breeding in my house...

JohnnyCyp
Posts: 75
Joined: Sun Mar 31, 2019 11:05 pm

Re: error_perm: 553 Can't open that file: Permission denied

Fri May 24, 2019 3:38 pm

Andyroo wrote:
Fri May 24, 2019 3:25 pm
The last line maybe the clue
home/pi/Project/pics/
That’s a relative directory to your current one.

Maybe it should be /home/pi/Project/pics/ ?
I tried it but nothing changes...

Andyroo
Posts: 3324
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: error_perm: 553 Can't open that file: Permission denied

Fri May 24, 2019 3:58 pm

Have you created that directory and given Pi (assuming you are running as Pi) access to it?

Remember Linux is case sensitive so Project and project are different.
Need Pi spray - these things are breeding in my house...

JohnnyCyp
Posts: 75
Joined: Sun Mar 31, 2019 11:05 pm

Re: error_perm: 553 Can't open that file: Permission denied

Fri May 24, 2019 4:24 pm

Andyroo wrote:
Fri May 24, 2019 3:58 pm
Have you created that directory and given Pi (assuming you are running as Pi) access to it?

Remember Linux is case sensitive so Project and project are different.
That's what i'm afraid , can you give me a good and completed guide about FTP ? I'm new in python and FTP and the only guide that i have used is this: https://bit.ly/2iCefJw
Also something happens in FileZilla where i explore my files in raspberry pi, now it doesn't show my directory address correctly for example the directory address: /home/pi/Project in FileZilla is shown as: /Project

Andyroo
Posts: 3324
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: error_perm: 553 Can't open that file: Permission denied

Fri May 24, 2019 5:41 pm

Not sure on the FTP guide - I started using it from the command line when Windows has three digits after it (3.11) :o Its the best way to learn each command. A quick Google found me this one http://ftpguide.com that explains each command (but not how to use the system) and the main definition (RFC) is here

A lot of hosting companies still allow FTP (though often restrict IP address / user accounts etc) so you may find something from them.

For FileZilla - I would head to their WiKi at https://wiki.filezilla-project.org/Documentation and you will find a tutorial there.

My guess is that you have used the remote site tree (normally on the right) and highlighted the /home/pi folder as the starting location or possible set the default home directory in the site / advanced options (that's on a Mac - no PC with it on here at the mo). Though I have FileZilla on the Mac I've no FTP site handy :oops: as no Pi is up and running :lol: to check for you.

Forgive me - I do not follow bit.ly links on this browser :arrow: :!:
Need Pi spray - these things are breeding in my house...

User avatar
Paeryn
Posts: 2564
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: error_perm: 553 Can't open that file: Permission denied

Fri May 24, 2019 6:05 pm

Depending on how your ftp server is set up, at a guess your ftp server is set to have a certain directory be the user's root directory so /home/pi/Project/pics would be translated to something else.

e.g. using vsftp as the server, if configured with chroot_local_user=yes and local_root=/home/vsftp then

Code: Select all

  ftp.cwd("/home/pi/Project/pics")
Would change into /home/vsftp/home/pi/Project/pics
She who travels light — forgot something.

Andyroo
Posts: 3324
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: error_perm: 553 Can't open that file: Permission denied

Fri May 24, 2019 6:09 pm

Why bother with an FTP server - FileZilla support SFTP over SSH - so as long as you have the Pi enabled for SSH your are in.

Not the most secure way but works well if you have no Samba running.

You do raise a good point though - we need to understand a little more from the OP about the Pi, its directory structure and how the program is running :)
Need Pi spray - these things are breeding in my house...

JohnnyCyp
Posts: 75
Joined: Sun Mar 31, 2019 11:05 pm

Re: error_perm: 553 Can't open that file: Permission denied

Fri May 24, 2019 7:16 pm

Andyroo wrote:
Fri May 24, 2019 6:09 pm
Why bother with an FTP server - FileZilla support SFTP over SSH - so as long as you have the Pi enabled for SSH your are in.

Not the most secure way but works well if you have no Samba running.

You do raise a good point though - we need to understand a little more from the OP about the Pi, its directory structure and how the program is running :)
I found out why FileZilla change the directory, is because i changed the ftp pointing directory. Anyway i want FTP server for my program it's not about the FileZilla. I make the setup correctly now for FTP and i give all the permission to folder and i think the problem is somewhere else in the line: ftp.storbinary('STOR ' + image_name, file). I got this problem now:
Traceback (most recent call last):
File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "/home/pi/project/functions.py", line 248, in ftpSession
ftp.storbinary('STOR ' + image_name, file) # send the file
File "/usr/lib/python2.7/ftplib.py", line 471, in storbinary
SMS has been sent!
conn = self.transfercmd(cmd, rest)
File "/usr/lib/python2.7/ftplib.py", line 376, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "/usr/lib/python2.7/ftplib.py", line 339, in ntransfercmd
resp = self.sendcmd(cmd)
File "/usr/lib/python2.7/ftplib.py", line 249, in sendcmd
return self.getresp()
File "/usr/lib/python2.7/ftplib.py", line 224, in getresp
raise error_perm, resp
error_perm: 553 Can't open that file: Permission denied

JohnnyCyp
Posts: 75
Joined: Sun Mar 31, 2019 11:05 pm

Re: error_perm: 553 Can't open that file: Permission denied

Fri May 24, 2019 7:52 pm

topguy wrote:
Fri May 24, 2019 12:32 pm
Have you tried to send the file with FTP manually ?
What is the command for upload file through ftp ?

Andyroo
Posts: 3324
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: error_perm: 553 Can't open that file: Permission denied

Fri May 24, 2019 8:19 pm

JohnnyCyp wrote:
Fri May 24, 2019 7:52 pm
topguy wrote:
Fri May 24, 2019 12:32 pm
Have you tried to send the file with FTP manually ?
What is the command for upload file through ftp ?
The command depends on the FTP client - it maybe PUT, it may be STOR or some programs do not have a command (e.g. scp) but assume the file is to be sent if it comes first in the list...

What client are you planning to use manually?

As for your error - without knowing the file and where it is on the system we are guessing.

The error could be due to:

1) The file being locked by another process
2) You not having access to the file due to security on the file
3) You not having access to the file due to security on the directory or directories above the one containing the file
Need Pi spray - these things are breeding in my house...

JohnnyCyp
Posts: 75
Joined: Sun Mar 31, 2019 11:05 pm

Re: error_perm: 553 Can't open that file: Permission denied

Fri May 24, 2019 9:20 pm

topguy wrote:
Fri May 24, 2019 12:32 pm
The command depends on the FTP client - it maybe PUT, it may be STOR or some programs do not have a command (e.g. scp) but assume the file is to be sent if it comes first in the list...

What client are you planning to use manually?
pure-ftpd
topguy wrote:
Fri May 24, 2019 12:32 pm

As for your error - without knowing the file and where it is on the system we are guessing.

The error could be due to:

1) The file being locked by another process
2) You not having access to the file due to security on the file
3) You not having access to the file due to security on the directory or directories above the one containing the file
I will check it again later, now i need to format the raspberry pi because i changed all the permission of all RPi files from root to ftp client by mistake and i can´t use any command in terminal even the sudo su don´t work, only the sudo root works but it needs a password and i don´t know it....

Return to “Python”