[英]FTP.delete(filename) from ftplib error
When I try to use ftp.delete()
from ftplib, it raises error_perm
, resp: 当我尝试使用ftplib中的
ftp.delete()
时,它引发error_perm
,分别是:
>>> from ftplib import FTP
>>> ftp = FTP("192.168.0.22")
>>> ftp.login("user", "password")
'230 Login successful.'
>>> ftp.cwd("/Public/test/hello/will_i_be_deleted/")
'250 Directory successfully changed.'
>>> ftp.delete("/Public/test/hello/will_i_be_deleted/")
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ftplib.py", line 520, in delete
resp = self.sendcmd('DELE ' + filename)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ftplib.py", line 243, in sendcmd
return self.getresp()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ftplib.py", line 218, in getresp
raise error_perm, resp
ftplib.error_perm: 550 Delete operation failed.
The directory exists, and "user" has sufficient permissions to delete the folder. 该目录存在,并且“用户”具有删除该文件夹的足够权限。
The site is actually a NAS (WD MyBookWorld) that supports ftp. 该站点实际上是支持ftp的NAS(WD MyBookWorld)。
Changing to parent directory and using command ftp.delete("will_i_be_deleted")
does not work either. 更改为父目录并使用命令
ftp.delete("will_i_be_deleted")
也不起作用。
"will_i_be_deleted" is an empty directory. “ will_i_be_deleted”是一个空目录。
ftp settings for WD MyBookWorld: WD MyBookWorld的ftp设置:
Service - Enable; Enable Anonymous - No; Port (Default 21) - Default
My solution to fix this ftplib.error_perm: 550 issue is to cwd to root directory of FTP server, and delete files by their full path as below. 解决此ftplib.error_perm:550问题的解决方案是将cwd转到FTP服务器的根目录,并按如下所示的完整路径删除文件。
ftp.cwd(‘.’)
directory = '/Public/test/hello/will_i_be_deleted/'
# delete files in dir
files = list(ftp.nlst(directory))
for f in files:
ftp.delete(f)
# delete this dir
ftp.rmd(directory)
You need to use the rmd
command, ie 您需要使用
rmd
命令,即
ftp.rmd("/Public/test/hello/will_i_be_deleted/")
rmd
is for removing directories, delete
is for removing files. rmd
用于删除目录, delete
用于删除文件。
The only method that works for me is that I can rename with the ftp.rename() command: 对我有用的唯一方法是,我可以使用ftp.rename()命令重命名:
eg 例如
ftp.mkd("/Public/Trash/")
ftp.rename("/Public/test/hello/will_i_be_deleted","/Public/Trash/will_i_be_deleted")
and then to manually delete the contents of Trash from time to time. 然后不时手动删除垃圾箱中的内容。
I do not know if this is an exclusive problem for the WD MyBookWorld ftp capabilities or not, but at least I got a workaround. 我不知道这是否是WD MyBookWorld ftp功能的排他性问题,但至少我有解决方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.