1

I am trying to download files using python's ftplib and I am running in an issue. When I run the script on my computer I am getting an error:

Traceback (most recent call last):
  File "ftp_get.py", line 20, in <module>
    ftps.retrbinary('RETR '+ filename, file.write)
  File "C:\Python27\lib\ftplib.py", line 710, in retrbinary
    conn.unwrap()
  File "C:\Python27\lib\ssl.py", line 771, in unwrap
    s = self._sslobj.shutdown()
socket.error: [Errno 0] Error

But when I run it on a server, it works flawlessly. It also worked on my computer earlier this morning but now I get the error. Python code below:

from ftplib import FTP_TLS
import os
import glob

user = "something"
passwd = "some_password"
ftps = FTP_TLS('domain')
ftps.login(user, passwd)
ftps.prot_p()       
filenames = ftps.nlst() 

for filename in filenames:
    local_filename = os.path.join('C:\\test2\\', filename)
    file = open(local_filename, 'wb')
    ftps.retrbinary('RETR '+ filename, file.write)
    print "Downloading - " + filename
    #ftps.delete (filename)
    #print "Deleting - " + filename
    file.close()

ftps.quit()

Why does it work on some computers and not others?

GreyHippo
  • 263
  • 1
  • 2
  • 14

1 Answers1

1

There seems to be a problem with accessing Pure-FTPd servers. It is documented here: https://bugs.python.org/issue25437 According to the report, there is a compatibility mode that you can set for the server. I didn't have access to the server in my case, so commented out ftps.prot_p(), which means that the data is send unencrypted.

dtf
  • 81
  • 1
  • 3
  • It's sad that this appears to have been fixed for Python 3.6, but apparently not for any previous versions as the ability for FTP servers to exhibit this behavior is considered a "new feature". Disabling encryption is not an option. – Darren Ringer Jun 09 '17 at 19:51
  • I'm using python 3.8 but facing the same issue. – variable Jan 20 '22 at 12:38