Using Python 3.3.0 and this script:

from ftplib import FTP_TLS

ftps = FTP_TLS('xxx.xx.xxx.xx')
ftps.sendcmd('USER myuname') 
ftps.sendcmd('PASS mypwd')
ftps.prot_p()          
ftps.retrlines('LIST') 
ftps.quit()

I get a connection failure due to timeout

>>> ================================ RESTART ================================
    >>> 
    Traceback (most recent call last):
    File "C:\Python33\fixFTP.py", line 2, in <module>
      ftps = FTP_TLS('xxx.xx.xxx.xx')
    File "C:\Python33\lib\ftplib.py", line 685, in __init__
      FTP.__init__(self, host, user, passwd, acct, timeout, source_address)
    File "C:\Python33\lib\ftplib.py", line 114, in __init__
      self.connect(host)
    File "C:\Python33\lib\ftplib.py", line 148, in connect
      source_address=self.source_address)
    File "C:\Python33\lib\socket.py", line 424, in create_connection
      raise err
    File "C:\Python33\lib\socket.py", line 415, in create_connection
      sock.connect(sa)
    TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

But I can connect using a FileZilla client using these credentials. Any clue as to why it times out using a script, but not using Filezilla client?

Did you try ftps = FTP_TLS('xxx.xx.xxx.xx', 'myuname', 'mypwd') ?

I did, but it never connects.
After modifying the script to:

from ftplib import FTP_TLS
import ftplib

ftps = FTP_TLS()

ftps.connect(host="xxx.xx.xxx.xx", port=990)
ftps.login(user="myuname", passwd="mypwd")
ftps.prot_p()
ftps.set_pasv(False)
ftps.retrlines('LIST') 

ftps.quit()

It still times out, but if I comment out the line

ftps.retrlines('LIST')

It connects fine.

With that line active (uncommented) the Filezilla server log shows this as the problem:

(000050)12/18/2013 12:25:49 PM - myuname (aa.bbb.cc.dd)> LIST
(000050)12/18/2013 12:25:49 PM - myuname (aa.bbb.cc.dd)> 150 Opening data channel for directory list.
(000050)12/18/2013 12:26:00 PM - myuname (aa.bbb.cc.dd)> 425 Can't open data connection.
(000050)12/18/2013 12:28:00 PM - myuname (aa.bbb.cc.dd)> 421 Connection timed out.
(000050)12/18/2013 12:28:00 PM - myuname (aa.bbb.cc.dd)> disconnected.

So it looks like the LIST command is getting through, but it can't get the data back to my script for some reason

Does ftps.dir() work ?

Apart from that, did you consider connecting to the server through the paramiko module ? Once connected, it is much more user-friendly because the paramiko api was designed for human beings, contrary to the ftp protocol. The hard part may be connection and authentication.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.