Error 0 when using ftplib

心已入冬 提交于 2019-12-08 13:02:33

问题


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?


回答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.



来源:https://stackoverflow.com/questions/32913943/error-0-when-using-ftplib

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!