使用 Python 连接到 Ubuntu 服务器

Connecting to an Ubuntu Server with Python

我的目标是用 Python 编写一个基本的 FTP 程序。首先,我需要获得更多的知识。我的问题是,如何使用 Python 连接到 Ubuntu 服务器(通过 VirtualBox 托管)?

我曾尝试使用 official Python website 上的页面,但在使用此

时出现 socket.error: [Errno 61] Connection refused 错误
from ftplib import FTP
ftp = FTP('jordan@10.0.0.12')

This 是我使用 ftp - FTP('10.0.0.12')

时得到的输出

Traceback (most recent call last): File "", line 1, in File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ftplib.py", line 120, in init self.connect(host) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ftplib.py", line 135, in connect self.sock = socket.create_connection((self.host, self.port), self.timeout) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 575, in create_connection raise err socket.error: [Errno 61] Connection refused

我可以在同一台机器上使用一个 FTP 程序,例如 Transmit(相同的端口,在 SFTP 上),它工作正常。

Python 的 ftplib 不支持 SFTP,因此使用 PySFTP 可以。

另一种方法是使用 paramiko。