Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 535
Satyajit Barik Avatar asked Sep 12 '25 02:09

Satyajit Barik


1 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.

like image 192
Martin Prikryl Avatar answered Sep 14 '25 17:09

Martin Prikryl