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

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

我在 Python 中连接到 FTP 时遇到错误:

 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

我的代码:

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

我认为连接设置是正确的,因为我可以在终端中连接:

您正在连接控制台中的 SFTP 客户端。

当您连接 Python 中的 FTP 库时。

FTP 和 SFTP 是完全不同的协议。如果你想在 Python 中复制你的 SFTP 连接,你需要使用 Python SFTP 模块,比如 Paramiko or pysftp.