2

I'm trying to get a connection established to a FTP server with SSL from within Python (v3.3.0). But I keep getting a timeout. I am NOT using port 990 as the SSL port (paranoid). Would that be the cause of this problem? And if so, how do I specify the port I am using?

Here's my script:

    from ftplib import FTP
    from ftplib import FTP_TLS

    ftps = FTP_TLS('ip address')

    ftps.auth()

    ftps.sendcmd('USER uname') 
    ftps.sendcmd('PASS password')

    ftps.prot_p()
    ftps.retrlines('LIST')

    ftps.close()

And here is the result:

Traceback (most recent call last):
  File "Scrpit name removed for posting", line 12, in <module>
    ftps.retrlines('LIST')
  File "C:\Python33\lib\ftplib.py", line 767, in retrlines
    conn = self.transfercmd(cmd)
  File "C:\Python33\lib\ftplib.py", line 381, in transfercmd
    return self.ntransfercmd(cmd, rest)[0]
  File "C:\Python33\lib\ftplib.py", line 742, in ntransfercmd
    conn, size = FTP.ntransfercmd(self, cmd, rest)
  File "C:\Python33\lib\ftplib.py", line 343, in ntransfercmd
    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

any advice would be greatly appreciated,

Thom Rogers
  • 1,385
  • 2
  • 20
  • 33

2 Answers2

4

After looking at the ftplib source, it doesn't seem to want to use any port but 21.

I think you should be able to work around this, something like

import ftplib

ftplib.FTP.port = 995     # or whatever port you are using
ftps = ftplib.FTP_TLS('hostname', 'user', 'pwd')
ftps.retrlines('LIST')
Hugh Bothwell
  • 55,315
  • 8
  • 84
  • 99
  • Thank you - after googling for a resolution I finally found this answer which fixes the issue. I can get a directory listing now! – InnerSphere May 16 '17 at 21:41
0

Set the port through the connect

import ftplib

ftps = ftplib.FTP_TLS()
ftps.connect ('hostname', 991)
KevinDTimm
  • 14,226
  • 3
  • 42
  • 60
  • I'm using the astandard port 21 for FTP, but not the standard 990 for SSL so how would I set the SSL port ? – Thom Rogers Nov 22 '13 at 20:10
  • As far as I can tell, using the method above connects to the designated port. – KevinDTimm Nov 22 '13 at 20:44
  • IN order to isolate the problem, I changed the SSL port to the default 990, but I still have the same timeout problem. I verified the port change took by manually connecting via Filezilla client – Thom Rogers Nov 22 '13 at 20:53