Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error_perm: 550 Permission denied

I'm learning web programming with Python, and still basically going through lectures/tutorial.

I'm trying to upload a file to a server. This is my code:

import ftplib
import sys

filename = sys.argv[1]
connect = ftplib.FTP("***.**.***.**")
connect.login("testuser","pass")
file = open(filename, "rb")
connect.storbinary("STOR " + filename, file)
connect.quit()

and this is the error I have:

File "C:\Users\test\putfile.py", line 8, in <module>
   connect.storbinary("STOR " + filename, file)
File "C:\Python27\lib\ftplib.py", line 471, in storbinary
   conn = self.transfercmd(cmd, rest)
File "C:\Python27\lib\ftplib.py", line 376, in transfercmd
   return self.ntransfercmd(cmd, rest)[0]
 File "C:\Python27\lib\ftplib.py", line 339, in ntransfercmd
   resp = self.sendcmd(cmd)
 File "C:\Python27\lib\ftplib.py", line 249, in sendcmd
   return self.getresp()
 File "C:\Python27\lib\ftplib.py", line 224, in getresp
   raise error_perm, resp
 ftplib.error_perm: 550 Permission denied.

testuser should have the permission to write files, since the folder is owned by him, and he has root privilege(was added in sudoer file).

the same thing happens if I add the line:

 connect.cwd('/testfolder')

I will get error_perm: 550 Failed to change directory.

However I can still read the existing files just fine (with connect.retrlines("RETR " + filename))

I'm pretty new about Python as well as Linux, so I don't have idea what I'm doing. I need some help.

like image 506
canikizu Avatar asked May 16 '14 01:05

canikizu


2 Answers

Perhaps this can help:

With FTP is not sufficient be owner of files and directories. The service and daemon FTP must be correctly configured in order to write and create files etc.

For example in Ubuntu:
Edit /etc/vsftpd.conf

And in the line

;write_enable=YES

Delete the semicolon

Finally restart the service:

sudo service  vsftpd restart
like image 90
fvel Avatar answered Oct 21 '22 06:10

fvel


I would check if you are in the right location. I got the same problem, and then I realised that I was in a different location that I intended, in the root folder, above "/public_html", so there was no folder that I wanted to enter, and I didn't have permissions to store any files.

You can check where you are this way:

print connect.pwd()

and what the contents of the current directory are:

print ftplib.FTP.dir(connect)

So, if you are in the root folder ("/"), above the "/public_html" and you want to change current directory to "/testfolder" you need to use:

connect.cwd('/public_html/testfolder')
like image 42
ellockie Avatar answered Oct 21 '22 06:10

ellockie