ftplib.error_perm: 553 无法创建文件.(Python 2.4.4) [英] ftplib.error_perm: 553 Could not create file. (Python 2.4.4)
问题描述
我正在写入要通过 FTP 访问的用户的主目录,因此权限应该不是问题.FTP 在 FileZilla 中工作.
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.
我检查了 vsftp.conf 并进行了 local_enable=YES
更改
I checked the vsftp.conf and made the local_enable=YES
change
在带有 Python 2.4.4(我无法升级)的 Debian4 系统上,我正在将此代码与 ftplib 一起使用
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?
推荐答案
你写的不是主目录,而是/full/path/of/file.txt
::p>
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)
您只能在 STOR
命令中使用文件名(一旦cwd"已经是正确的目标路径):
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)
这篇关于ftplib.error_perm: 553 无法创建文件.(Python 2.4.4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!