admin管理员组文章数量:1333439
I am building a FTP server for a project and I want to use self signed certificate. For this I am using pyftpdlib
library and importing TLS_FTPHandler
from it. But VS code is not accepting it.
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler,TLS_FTPHandler
from pyftpdlib.servers import FTPServer
import ssl
def run_secure_ftps_server():
# Set up user authorization
authorizer = DummyAuthorizer()
authorizer.add_user("ftp_user", "ftp_password", ".", perm="elradfmw")
authorizer.add_anonymous(".", perm="elr") # Optional: Anonymous login with limited access
# Create an FTPS handler
handler = TLS_FTPHandler
handler.authorizer = authorizer
# Set up SSL/TLS for FTPS
certfile = "server.pem" # Path to your SSL certificate
ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
ssl_context.load_cert_chain(certfile)
handler.ssl_context = ssl_context
# Force encryption on control and data channels
handler.tls_control_required = False
handler.tls_data_required = True
# Start the FTPS server
ftps_server = FTPServer(("0.0.0.0", 21), handler)
print("FTPS Server running on port 2121 with secure TLS...")
ftps_server.serve_forever()
if __name__ == "__main__":
# Generate a self-signed certificate if it doesn't exist
import os
if not os.path.exists("server.pem"):
print("Generating self-signed SSL certificate...")
os.system("openssl req -new -x509 -days 365 -nodes -out server.pem -keyout server.pem")
run_secure_ftps_server()
VS code is giving the reply as
from pyftpdlib.handlers import FTPHandler,TLS_FTPHandler
ImportError: cannot import name 'TLS_FTPHandler' from 'pyftpdlib.handlers' (C:\Users\Faaez\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyftpdlib\handlers.py). Did you mean: 'FTPHandler'?
I have seen all the documentation and the version of all the libraries online but still no clue. I have asked diff AI models and online forums but still no clue. Because of this, I can't connect the client to server. Though, I am using the same versions.
本文标签: pythonProblem in TLSFTPHandler fom pyftpdlib libraryStack Overflow
版权声明:本文标题:python - Problem in TLS_FTPHandler fom pyftpdlib library - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742304559a2449655.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论