Python FTP: "TimeoutError: [Errno 110] Connection timed out" but I can connect with sftp in terminal

10,984

You are connecting with an SFTP client in the console.

While you are connecting with an FTP library in Python.

FTP and SFTP are completelly different protocols. If you want to replicate your SFTP connection in Python, you need to use a Python SFTP module, like Paramiko or pysftp.

Share:
10,984
Satyajit Barik
Author by

Satyajit Barik

Updated on June 04, 2022

Comments

  • Satyajit Barik
    Satyajit Barik almost 2 years

    I'm getting error while connecting to FTP in Python:

     server.connect('68.183.91.171')
      File "/usr/lib/python3.6/ftplib.py", line 152, in connect
        source_address=self.source_address)
      File "/usr/lib/python3.6/socket.py", line 724, in create_connection
        raise err
      File "/usr/lib/python3.6/socket.py", line 713, in create_connection
        sock.connect(sa)
    TimeoutError: [Errno 110] Connection timed out
    
    

    My code:

    import ftplib
    server = ftplib.FTP()
    server.connect('68.183.91.171')
    server.login('root','password')
    server.dir()
    

    I think the connection settings are correct as I can connect in terminal:

    enter image description here