Reputation: 4740
I don't know what I'm doing wrong but this small ftp code won't transfer files. I keep getting
File "example.py", line 11, in ? ftp.storlines("STOR " + file, open(file))
ftplib.error_perm: 550 /home/helen/docs/example.txt: Operation not permitted
Here is the code:
import ftplib
file = '/home/helen/docs/example.txt'
ftp = ftplib.FTP('domain', 'user', 'password')
print "File List: "
files = ftp.dir()
ftp.cwd("/upload/")
ftp.storlines("STOR " + file, open(file))
f.close()
s.quit()
Any help would be appreciated.
Upvotes: 0
Views: 3920
Reputation: 123413
I think the error you're getting is that you're adding the entire file path to the first argument in thestorlines()
call. Instead, just specify the file name itself:
import os
ftp.storlines("STOR " + os.path.basename(file), open(file))
You might want to consider changingfile
tofilepath
,since that's what it really is (plus you will no longer be hiding the built-in function & type of the same name).
Upvotes: 6
Reputation: 3207
550 error literally means according to wikipedia "550 Requested action not taken. File unavailable (e.g., file not found, no access)."
http://en.wikipedia.org/wiki/List_of_FTP_server_return_codes
are you sure you have the right permissions?
try this
ftp = ftplib.FTP('domain')
ftp.login('user','pass')
i think the object creation was just a little jacked up.
Upvotes: 0