1

I am trying to connect to ftp.debian.org, using the very basic example shown in the official Python documentation (https://docs.python.org/2/library/ftplib.html) but I keep getting errors. Hope someone can point out where I'm going wrong.


    import socket
    from ftplib import FTP

    try:
        print("Attempting login...")
        ftp = FTP('ftp.debian.org')
        ftp.login()
        # print("Listing directory...")
        # ftp.retrlines('LIST')
        # print("Ending the connection...")
        # ftp.quit()
    except socket.timeout:
        print("Socket timeout caught")
    finally:
        print("FTP connection test has ended.")

The error I receive is the following:
Traceback (most recent call last): 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

srinathmsn
  • 11
  • 3
  • 1
    Your code looks good. The server `ftp.debian.org` does not have an FTP server on port 21, though. If you try the same code with `ftp.redhat.com`, it works. – Björn Marschollek Aug 01 '19 at 19:55
  • 1
    also see https://stackoverflow.com/questions/44106200/python-ftplib-winerror-10060 – Manvir Aug 01 '19 at 19:56
  • @Tyger: Thank you for the link. Looks like the OP had a timeout error but I don't think the server is listening on port 21, as pointed out by Bjorn above. – srinathmsn Aug 06 '19 at 19:08
  • @BjörnMarschollek: Thanks for the heads up. I tried with **ftp.redhat.com** and got the same error albeit the server listening on port 21. I believe my firewall or some security program is preventing me from using FTP (I'm running this script on my work computer btw). – srinathmsn Aug 06 '19 at 19:11

1 Answers1

1

Looks like there is a problem with the address you are trying to connect. I tried your code and got a 'Connection refused'. Since the address itself seems to be for ftp, I tried to check if port 21 - standard for ftp - was open and it doesn't seem like it. I would assume then that this particular ftp server was setup on a port other than the standard.

Now you could try and find out which port is set up for ftp at that address and specify it on your code, or if it is just a test, try with another server.

https://pentest-tools.com/network-vulnerability-scanning/tcp-port-scanner-online-nmap#

Luís Flávio
  • 171
  • 1
  • 12
  • I'm testing the script on my work computer so I assume I'm not allowed to FTP willy nilly. That being said, do you know any FTP servers that would allow me to logon anonymously without any credentials? I'd like to test this script at home. (I tried **ftp.redhat.com** but couldn't make it past the password prompt) – srinathmsn Aug 06 '19 at 19:15