1

I'm trying to do a FTP TLS with python 3.6.2 on windows. Follows the code:

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()

But something gets wrong, I guess it's about the server certification. although even return error, the file is sent to the server.

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)

Using FileZilla works just fine, but before connecting, pops up a msg about certification and after acceptance connects, that reads:

Unknown certificate

The server's certificate is unknown. Please carefully examine the certificate to make sure the server can be trusted.

spectras
  • 13,105
  • 2
  • 31
  • 53
M. Alexandre
  • 61
  • 1
  • 4
  • From that error, server certificate looks invalid. You should look at the documentation to see how the lib reacts in that case (or just fix the certificate). By the way, welcome to SO, please copy actual messages and don't post screenshots. The point of SO is to have a searchable database of quality answers to quality questions, which means text. I edited your question for you this time :). – spectras Oct 02 '17 at 18:01

0 Answers0