Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k views
in Technique[技术] by (71.8m points)

linux - ftplib.error_perm: 553 Could not create file. (Python 2.4.4)

I am writing to the home directory of the user I'm FTPing into, so permissions shouldn't be an issue. FTP works in FileZilla.

I checked the vsftp.conf and made the local_enable=YES change

On a Debian4 system with Python 2.4.4 (I can't upgrade it), I am using this code with ftplib

>>> f = ftplib.FTP('address', 'user', 'password')
>>> f.cwd('/home/user/some/dir/')
'250 Directory successfully changed.'
>>> myfile = '/full/path/of/file.txt'
>>> o = open(myfile, 'rb')
>>> f.storbinary('STOR ' + myfile, o)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/ftplib.py", line 415, in storbinary
    conn = self.transfercmd(cmd)
  File "/usr/lib/python2.4/ftplib.py", line 345, in transfercmd
    return self.ntransfercmd(cmd, rest)[0]
  File "/usr/lib/python2.4/ftplib.py", line 327, in ntransfercmd
    resp = self.sendcmd(cmd)
  File "/usr/lib/python2.4/ftplib.py", line 241, in sendcmd
    return self.getresp()
  File "/usr/lib/python2.4/ftplib.py", line 216, in getresp
    raise error_perm, resp
ftplib.error_perm: 553 Could not create file.

Any ideas why it fails?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are not writing to a home directory, you are writing to /full/path/of/file.txt:

myfile = '/full/path/of/file.txt'
...
f.storbinary('STOR ' + myfile, o)

You have to use a file name only with the STOR command (once the "cwd" is already the correct target path):

f.cwd('/home/user/some/dir/')
f.storbinary('STOR file.txt', o)

or a correct absolute path for the remote host:

f.storbinary('STOR /home/user/some/dir/file.txt', o)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...