Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8675779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:01:47+00:00 2026-06-12T20:01:47+00:00

HI I am trying to download file from FTPS using python 2.7. Below is

  • 0

HI I am trying to download file from FTPS using python 2.7. Below is my code Here I am gating unexceptional IO error. While this code is running on UNIX and Python 2.7. I tried on windows with same code and its working fine. But on unix its not working as excepted.

Not getting where I am doing mistake.

#!/usr/bin/env python

import ftplib  
import os
import datetime
import sys
from ftplib import FTP_TLS

try:
  ftps = FTP_TLS(server)
  ftps.debug(3)
  ftps.connect(host=server,port=portno)
  ftps.auth()    
  ftps.login(username, password)
  ftps.prot_p()    
  ftplogin=True
except Exception, e:
    logger.error(e)

# Change to the proper directory
if ftplogin:
    try:
      ftps.cwd(directory)
      filelist = [] #to store all files
      ftps.retrlines('LIST',filelist.append)    # append to list
      is_file_exist=False       
      if len(filelist)>0 :#do something                   
          is_file_exist = True

      if  is_file_exist :
         print "file exist"
          ##Loop through matching files and download each one individually
          try:
              for filename in ftps.nlst(filematch):
                  local_filename = os.path.join(downloadpath, filename)
                  fhandle = open(local_filename, 'wb')                    
                  logger.info('Getting ' + filename)
                  ftps.retrbinary('RETR ' + filename, fhandle.write)
                  fhandle.close()             #                    
              ftps.quit()    
              logger.info("File download successfull")
          except Exception , e:
              print e
              logger.error(e)
     else :
       logger.info("There is no file for processing")  

 except IOError as eo:
    print "I/O error ({0}):{1}".format(eo.errno,eo.strerror)
 except Exception, e:
   directoryFound=False
   logger.error(e)
   print e
 except :
   print "Unexpected erro:", sys.exc_info()[0]

Note: Please ignore Indent as I am copying the code here and its in proper formatted in .Py file

Code is breaking with below error

Abc.txt*
Abc1.txt*
*get* '220 208.235.248.3 FTP server ready\r\n'
*resp* '220 208.235.248.3 FTP server ready'
*cmd* 'AUTH TLS'
*put* 'AUTH TLS\r\n'
*get* '234 AUTH TLS successful\r\n'
*resp* '234 AUTH TLS successful'
*cmd* 'USER Username'
*put* 'USER Username \r\n'
*get* '331 Password required for Username.\r\n'
*resp* '331 Password required for Username.'
*cmd* 'PASS ********'
*put* 'PASS ********\r\n'
*get* '230 User Username logged in.\r\n'
*resp* '230 User Username logged in.'
*cmd* 'PBSZ 0'
*put* 'PBSZ 0\r\n'
*get* '200 PBSZ 0 successful\r\n'
*resp* '200 PBSZ 0 successful'
*cmd* 'PROT P'
*put* 'PROT P\r\n'
*get* '200 Protection set to Private\r\n'
*resp* '200 Protection set to Private'
2012-09-12 05:01:54,029 - __main__ - INFO - Server login successful
changeing directory
*cmd* 'CWD /prod/hm'
*put* 'CWD /prod/hm\r\n'
*get* '250 CWD command successful.\r\n'
*resp* '250 CWD command successful.'
Directory changed/prod/hm
filelist init
*cmd* 'TYPE A'
*put* 'TYPE A\r\n'
*get* '200 Type set to A\r\n'
*resp* '200 Type set to A'
*cmd* 'PASV'
*put* 'PASV\r\n'
*get* '227 Entering Passive Mode (208,235,248,3,232,171).\r\n'
*resp* '227 Entering Passive Mode (208,235,248,3,232,171).'
*cmd* 'NLST'
*put* 'NLST\r\n'
*get* '150 Opening ASCII mode data connection for file list\r\n'
*resp* '150 Opening ASCII mode data connection for file list'
*retr* 'Abc.txt\r\n'
*retr* 'Abc1.txt\r\n'
*retr* ''
I/O error (0):Error

I have change the file name and FTPS details for security. 🙂

I tried with lot of option but there is no workaround. If I change this coed with FTP and make require code changes like Comment ftps.auth(), ftps.prot_p() then it working fine but for FTPS is not working.

I am not getting the error as well to explore
There is no information available on Internet as I search lot but no solution
Please help 

I am using ftplib over ftp_tls class and python2.7 on unix

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:01:48+00:00Added an answer on June 12, 2026 at 8:01 pm

    Its seems ftplib.py not working properly on UNIX in python2.7 I don’t know whether any one getting this error on letest version of python like python 3.2 . In ftplib.py under FTP_TLS class retrbinary and retrlines command having conn.unwrap() method. This method not closing connection and reopen properly on unix. instead of conn.unwrap() if we can use conn.close() it will work.
    Please do the below change inside ftplib.py

     def retrbinary(self, cmd, callback, blocksize=8192, rest=None):
         ...
         ...
          if isinstance(conn, ssl.SSLSocket):
             ##conn.unwrap()
             conn.close()
         ....
    

    and

     def retrlines(self, cmd, callback = None):
         ....
         ....
             if isinstance(conn, ssl.SSLSocket):
             ##conn.unwrap()
             conn.close()
         .....
             conn.close()
    

    I dont know whether its having any impact on other functionality. Please cross check before implementing this modification on production

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to download a file from a website using python and mechanize.
I'm trying to download file with Python using IE: from win32com.client import DispatchWithEvents class
I am trying to download a file from a website using the following code:
i'm trying to download .zip file from bluehost server to my computer. Like this
On Ubuntu, I am trying to download a file (from a script) using wget.
I'm trying to download the XLS file from this page: http://www.nordpoolspot.com/Market-data1/Elspot/Area-Prices/ALL1/Hourly/ (click on Export
I am trying to implement an Asynchronous file download from a web server using
I'm trying out http requests to download a pdf file from google docs using
I'm trying to download a file from the internet, but I get the error
I am trying to download a file from a site using perl. I chose

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.