简体   繁体   English

连接被拒绝FTP python 2.7

[英]Connection refused FTP python 2.7

I am using the ftplib module and want to connect to FTP on my localhost. 我正在使用ftplib模块,并想连接到本地主机上的FTP。 I am using the following code example: 我正在使用以下代码示例:

import ftplib
f = ftplib.FTP()
f.connect("localhost")
f.login()

ls=[]
f.retrlines('MLSD',ls.append)
for entry in ls:
    print entry

It gives me a socket.error: [Errno 61] Connection refused 它给了我一个socket.error: [Errno 61] Connection refused

How do i connect to my localhost and what am i doing wrong? 我如何连接到本地主机,我在做什么错? Eventually i would want to send files from a client code to server code using ftplib, both running on the same machine. 最终,我想使用ftplib将文件从客户端代码发送到服务器代码,两者都在同一台计算机上运行。 This is for a project, i know in reality you wouldn't have both on the same machine. 这是一个项目,我知道实际上您不会在同一台计算机上同时拥有这两者。

I am guessing the socket.error exception occurs on line 3, where you have connect() . 我猜想socket.error异常发生在第3行,那里有connect()

Connection refused indicates that the operating system or the firewall rejected the connection. Connection refused表示操作系统或防火墙拒绝了连接。 The most likely reason is that you don't actually have an FTP server running on your local machine. 最可能的原因是您实际上没有在本地计算机上运行FTP服务器。

You didn't say whether you do or you don't, and you didn't say what operating system you're using. 您没有说自己是否做过,也没有说您正在使用什么操作系统。 But by default, operating systems don't come with an FTP server installed and running. 但是默认情况下,操作系统没有安装并运行FTP服务器。 So you need to install a compatible FTP server . 因此,您需要安装兼容的FTP服务器 A good one to consider is FileZilla Server. 一个不错的考虑因素是FileZilla Server。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM