我已经使用ftplib创建了一个FTP客户端。我在其中一台Ubuntu虚拟机和另一台客户机上运行服务器。我想用ftplib连接到服务器,我按照以下方式进行:无法使用ftplib的IP地址(Python)
host = "IP address of the server"
port = "Port number of the server"
ftpc = FTP()
ftpc.connect(host, port)
我收到以下错误!
Traceback (most recent call last):
File "./client.py", line 54, in <module>
ftpc.connect(host, port)
File "/usr/lib/python2.7/ftplib.py", line 132, in connect
self.sock = socket.create_connection((self.host, self.port), self.timeout)
File "/usr/lib/python2.7/socket.py", line 571, in create_connection
raise err
socket.error: [Errno 111] Connection refused
当我浏览python的文档时,我可以看到ftplib仅用于域名,如FTP(“域名”)。我可以使用IP地址而不是域名吗?就我而言,我无法理解错误。如果有人能帮助我,这将是非常棒的。
另外,如果我在我的服务器上使用端口21,我得到套接字错误:连接被拒绝。我如何使用端口21作为我的FTP服务器?
谢谢。
连接拒绝意味着您的代码实际上已到达远程地址,但该计算机不运行ftp服务器,或者端口的防火墙已被屏蔽。使用dns名称并不意味着什么 - 它只是一个抽象层。无论如何,所有东西都在IP下运行。 – 2013-05-07 20:58:00
谢谢你的回复。我如何检查港口的防火墙?在承载FTP服务器的服务器上运行 – harnex 2013-05-07 21:07:08
,将'iptables --list'作为'root'或'sudo iptables --list'运行。 – pcurry 2013-05-07 21:10:18