Skip to content
Advertisement

Error after FTPS transfer finishes with Python ftplib

I’m trying to upload file into FTPS server (Wing FTP Server / Cerberus FTP Server 8) with following script.

from ftplib import FTP_TLS
ftps = FTP_TLS('192.168.133.69')
ftps.login('1011', '7c52xK9')      
ftps.prot_p()
filename = 'upload.pdf'
myfile = open(filename, 'rb')
ftps.storbinary('STOR %s' % filename, myfile)
myfile.close()
ftps.close()

But I keep getting this error.

line 7, in <module>
    ftps.storbinary('STOR %s' % filename, myfile)
  File "C:Python27libftplib.py", line 769, in storbinary
    conn.unwrap()
  File "C:Python27libssl.py", line 823, in unwrap
    s = self._sslobj.shutdown()
error: [Errno 0] Error

This is FTPS server log.

[04] Thu, 02 Feb 2017 19:41:23 (0000062) 220 Wing FTP Server ready... (UNREGISTERED WING FTP SERVER)
[03] Thu, 02 Feb 2017 19:41:23 (0000062) AUTH TLS
[04] Thu, 02 Feb 2017 19:41:23 (0000062) 234 AUTH command OK. Initializing TLS connection.
[03] Thu, 02 Feb 2017 19:41:23 (0000062) USER 1011
[04] Thu, 02 Feb 2017 19:41:23 (0000062) 331 Password required for 1011
[03] Thu, 02 Feb 2017 19:41:23 (0000062) PASS **********
[04] Thu, 02 Feb 2017 19:41:23 (0000062) 230 User 1011 logged in.
[03] Thu, 02 Feb 2017 19:41:23 (0000062) PBSZ 0
[04] Thu, 02 Feb 2017 19:41:23 (0000062) 200 Command okay. PBSZ=0.
[03] Thu, 02 Feb 2017 19:41:23 (0000062) PROT P
[04] Thu, 02 Feb 2017 19:41:23 (0000062) 200 Encrypting Data Channel.
[03] Thu, 02 Feb 2017 19:41:23 (0000062) TYPE I
[04] Thu, 02 Feb 2017 19:41:23 (0000062) 200 Type set to I
[03] Thu, 02 Feb 2017 19:41:23 (0000062) PASV
[04] Thu, 02 Feb 2017 19:41:23 (0000062) 227 Entering Passive Mode (192,168,133,69,4,21)
[03] Thu, 02 Feb 2017 19:41:23 (0000062) STOR upload.pdf
[04] Thu, 02 Feb 2017 19:41:23 (0000062) 150 Opening BINARY mode data connection for file transfer.
[04] Thu, 02 Feb 2017 19:41:23 (0000062) 226 File received successful. Transferred:0Bytes;Average speed is:0.000KB/s

Can anyone tell me what is wrong?!!

PS: I don’t know it matters or not but i can easily download from this FTPS server and only cant upload into it.

Thanks in advance


I tried with FileZilla as “Martin Prikryl” suggested and now I have following error.

line 7, in <module>
    ftps.storbinary('STOR %s' % filename, myfile)
  File "C:Python27libftplib.py", line 760, in storbinary
    conn = self.transfercmd(cmd, rest)
  File "C:Python27libftplib.py", line 376, in transfercmd
    return self.ntransfercmd(cmd, rest)[0]
  File "C:Python27libftplib.py", line 713, in ntransfercmd
    server_hostname=self.host)
  File "C:Python27libssl.py", line 363, in wrap_socket
    _context=self)
  File "C:Python27libssl.py", line 611, in __init__
    self.do_handshake()
  File "C:Python27libssl.py", line 840, in do_handshake
    self._sslobj.do_handshake()
SSLEOFError: EOF occurred in violation of protocol (_ssl.c:661)

This is FileZilla server Log.

(000002)2017/02/03 11:00:54 ق.ظ - (not logged in) (127.0.0.1)> Connected on port 21, sending welcome message...
(000002)2017/02/03 11:00:54 ق.ظ - (not logged in) (127.0.0.1)> 220-FileZilla Server 0.9.59 beta
(000002)2017/02/03 11:00:54 ق.ظ - (not logged in) (127.0.0.1)> 220-written by Tim Kosse (tim.kosse@filezilla-project.org)
(000002)2017/02/03 11:00:54 ق.ظ - (not logged in) (127.0.0.1)> 220 Please visit https://filezilla-project.org/
(000002)2017/02/03 11:00:54 ق.ظ - (not logged in) (127.0.0.1)> AUTH TLS
(000002)2017/02/03 11:00:54 ق.ظ - (not logged in) (127.0.0.1)> 234 Using authentication type TLS
(000002)2017/02/03 11:00:54 ق.ظ - (not logged in) (127.0.0.1)> TLS connection established
(000002)2017/02/03 11:00:54 ق.ظ - (not logged in) (127.0.0.1)> USER 1011
(000002)2017/02/03 11:00:54 ق.ظ - (not logged in) (127.0.0.1)> 331 Password required for 1011
(000002)2017/02/03 11:00:54 ق.ظ - (not logged in) (127.0.0.1)> PASS *******
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> 230 Logged on
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> PBSZ 0
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> 200 PBSZ=0
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> PROT P
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> 200 Protection level set to P
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> TYPE I
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> 200 Type set to I
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> PASV
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> 227 Entering Passive Mode (127,0,0,1,231,157)
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> STOR upload.pdf
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> 150 Opening data channel for file upload to server of "/upload.pdf"
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> 450 TLS session of data connection has not resumed or the session does not match the control connection
(000002)2017/02/03 11:02:54 ق.ظ - 1011 (127.0.0.1)> 421 Connection timed out.
(000002)2017/02/03 11:02:54 ق.ظ - 1011 (127.0.0.1)> disconnected.

Advertisement

Answer

It’s probably some firewall/NAT/proxy on the way between you and the server that interferes with the transfer connection.

As the problem seems to happen during teardown of the TLS/SSL connection, after an actual transfer finishes, some clients may simply choose to ignore the error (or they do not even notice it).


Related question with some workarounds:
ftplib storbinary with FTPS is hanging/never completing

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement