- 論壇徽章:
- 0
|
環(huán)境 python 2.7 pyftpdlib 0.7.0 ubuntu 12.04
執(zhí)行python ftps-server.py
用 python 2.7 帶的ftplib就可以
In [1]: from ftplib import FTP_TLS
In [2]: ftps = FTP_TLS('127.0.0.1','user','bbbb')
error_perm: 530 Authentication failed.
使用lftp 登錄 ftps時提示錯誤
lftp ftps://fa:aa@127.0.0.1:21
lftp fa@127.0.0.1:~> ls
ls: Fatal error: gnutls_handshake: A TLS packet with unexpected length was received.
大家?guī)兔纯词裁丛蛄耍?img src="static/image/smiley/default/icon_question.gif" smilieid="63" border="0" alt="" />
ftps_server.py代碼如下:- from pyftpdlib import ftpserver
- from pyftpdlib.contrib.handlers import TLS_FTPHandler,FTPHandler
- import md5
- class MyHandler(TLS_FTPHandler):
- def on_login(self, username):
- # do something when user login
- print 'username:%s' % username
-
- def on_login_failed(self, username, password):
- print 'afasfd-----------------------------------'
- print 'password:%s' % password
- def on_logout(self, username):
- # do something when user logs out
- pass
-
- def on_file_sent(self, file):
- # do something when a file has been sent
- pass
- def on_file_received(self, file):
- # do something when a file has been received
- pass
-
- def on_incomplete_file_sent(self, file):
- # do something when a file is partially sent
- pass
- def on_incomplete_file_received(self, file):
- # remove partially uploaded files
- pass
-
-
- authorizer = ftpserver.DummyAuthorizer()
- authorizer.add_user('user', '12345', '.', perm='elradfmw')
- #authorizer.add_anonymous('.')
- handler = MyHandler
- handler.certfile = 'keycert.pem'
- handler.authorizer = authorizer
- # requires SSL for both control and data channel
- #handler.tls_control_required = True
- #handler.tls_data_required = True
- ftpd1 = ftpserver.FTPServer(('127.0.0.1', 21), handler)
- ftpd1.serve_forever()
復制代碼 |
|