ftplib.error_perm:553无法创建文件。 (Python 2.4.4)

时间:2017-11-06 05:25:55

标签: python linux ftp ftplib

我正在写入用户的主目录,因此权限不应成为问题。 FTP适用于FileZilla。

我检查了vsftp.conf并进行了local_enable=YES更改

在使用Python 2.4.4的 Debian4 系统上(我无法对其进行升级),我在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.

任何想法失败的原因?

1 个答案:

答案 0 :(得分:2)

您没有写入主目录,而是写信给/full/path/of/file.txt

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

您必须仅使用STOR命令使用文件名(一旦&#34; cwd&#34;已经是正确的目标路径):

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

或远程主机的正确绝对路径:

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