:::: MENU ::::

Monthly Archives / October 2014

  • Oct 07 / 2014
  • 0
Python

Use FTPS (SSL/TLS) with Python 2.6

By default, Python 2.6 does not permit to open an FTPS connection (using SSL/TLS) and restricts the use of non secure protocol FTP.
However, it’s possible to get around this lack by using the FTP library available since version 2.7, which is fully compatible and supported with 2.6.

You can get the library directly from official sources or through the link below:
http://www.bggofurther.com/wp-content/uploads/2014/10/ftplib.zip

Once the library copied (you can either replace the existing library or integrate it locally), you can so open an FTPS connection by using the FTP_TLS library. For example:

>>> from ftplib import FTP_TLS
>>> ftp = FTP_TLS('ftp.example.org')  # connect to host, default port
>>> ftp.login()                       # login anonymously before securing control channel
'230 Guest login ok, access restrictions apply.'
>>> ftp.prot_p()                      # securing data connection explicitly
>>> ftp.cwd('/')                      # change working directory to the root
>>> ftp.retrlines('LIST')             # list directory contents
total 7
drwxr-xr-x   8 ftpuser     ftpgroup       1024 Jan  3  2012 .
drwxr-xr-x   8 ftpuser     ftpgroup       1024 Jan  3  2012 ..
drwxr-xr-x   2 ftpuser     ftpgroup       1024 Oct  7  2013 bin
d-wxrwxr-x   2 ftpuser     ftpgroup       1024 Sep 17  2013 etc
drwxr-xr-x   2 ftpuser     ftpgroup       1024 Nov 23  2013 lib
drwxr-xr-x   3 ftpuser     ftpgroup       1024 Oct  7  2013 usr
-rw-r--r--   1 ftpuser     ftpgroup        312 Aug 18  2013 __init__.py
'226 Transfer complete.'
>>> ftp.quit()
'221 Goodbye.'

You can so maintain your applications running with Python 2.6 and use a secure connection for FTP!

Question ? Contact