编程语言
首页 > 编程语言> > Python-ftplib.error_perm:550将文件存储为匿名用户时权限不足

Python-ftplib.error_perm:550将文件存储为匿名用户时权限不足

作者:互联网

我创建了一个python FTP客户端和一个服务器.我将python pftpdlib用于服务器,将ftplib用于客户端.我能够成功启动服务器,并通过python客户端连接到服务器.但是,当我需要在服务器中存储文件时,出现以下错误.

File "/usr/lib/python2.7/ftplib.py", line 471, in storbinary
    conn = self.transfercmd(cmd, rest)
  File "/usr/lib/python2.7/ftplib.py", line 376, in transfercmd
    return self.ntransfercmd(cmd, rest)[0]
  File "/usr/lib/python2.7/ftplib.py", line 339, in ntransfercmd
    resp = self.sendcmd(cmd)
  File "/usr/lib/python2.7/ftplib.py", line 249, in sendcmd
    return self.getresp()
  File "/usr/lib/python2.7/ftplib.py", line 224, in getresp
    raise error_perm, resp
ftplib.error_perm: 550 Not enough privileges.

以下是我的服务器的来源

from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
authorizer = DummyAuthorizer()
authorizer.add_anonymous("/home/deepal/anonymous")
handler = FTPHandler
handler.authorizer = authorizer

handler.banner = "Server Ready.."

address = ("",21)
server = FTPServer(address, handler)

server.max_cons = 10
server.serve_forever()

接下来是客户.

from ftplib import FTP
hostname = sys.argv[2]
ftp = FTP(hostname)
ftp.login()
filepath = "/home/deepal/Desktop/infile"
localfile = open(filepath,"rb")
ftp.storbinary("STOR "+str(os.path.basename),localfile)

我需要匿名将文件传输到服务器.有人可以帮助我指出出现上述错误的代码出了什么问题吗?这样可以匿名存储文件吗?

谢谢.

解决方法:

我自己解决了.我需要给匿名用户适当的权限.换线

authorizer.add_anonymous("/home/deepal/anonymous")

authorizer.add_anonymous("/home/deepal/anonymous", perm='elradfmwM')

工作了.

标签:ftplib,python
来源: https://codeday.me/bug/20191029/1959517.html