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

Question:

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 with

sftp 68.183.91.171

enter image description here

Asked By: Satyajit Barik

||

Answers:

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.

Answered By: Martin Prikryl
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.