我试图在Windows上使用python 3.6.2进行FTP TLS。遵循代码:
import ftplib
ftp = ftplib.FTP_TLS()
ftp.connect(host, port)
ftp.login(usr, pwd)
ftp.prot_p()
fh = open(r'C:\\Users\\AlexandreMagno\\Desktop\\teste2.txt', 'rb')
ftp.storbinary('STOR teste2.txt', fh)
fh.close()
但是出了点问题,我想它是关于服务器认证的。虽然返回错误,但文件仍会发送到服务器。
Traceback (most recent call last):
File "D:/Google Drive/_ALEXANDRE/_ESTUDO/_PHYTON/_Códigos/FTP GESMAN/FTP GESMAN.py", line 26, in <module>
ftp.storbinary('STOR teste2.txt', fh)
File "C:\Program Files\Anaconda3\lib\ftplib.py", line 502, in storbinary
with self.transfercmd(cmd, rest) as conn:
File "C:\Program Files\Anaconda3\lib\ftplib.py", line 397, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "C:\Program Files\Anaconda3\lib\ftplib.py", line 799, in ntransfercmd
server_hostname=self.host)
File "C:\Program Files\Anaconda3\lib\ssl.py", line 401, in wrap_socket
_context=self, _session=session)
File "C:\Program Files\Anaconda3\lib\ssl.py", line 808, in __init__
self.do_handshake()
File "C:\Program Files\Anaconda3\lib\ssl.py", line 1061, in do_handshake
self._sslobj.do_handshake()
File "C:\Program Files\Anaconda3\lib\ssl.py", line 683, in do_handshake
self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:749)
使用FileZilla工作得很好,但在连接之前,会弹出一个关于认证的消息,在接受连接之后,它会显示:
未知证书
服务器的证书未知。请仔细检查证书,以确保服务器可以信任。