Ftplib ConnectionRefusedError:[Errno 111]连接被拒绝(python 3.5) [英] Ftplib ConnectionRefusedError: [Errno 111] Connection refused (python 3.5)

查看:193
本文介绍了Ftplib ConnectionRefusedError:[Errno 111]连接被拒绝(python 3.5)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应该连接到FTP的脚本

I have a script that should connect to a FTP

from ftplib import FTP

with FTP('IP') as ftp:
   ftp.login(user='my user', passwd='my password')
   ftp.cwd('/MY_DIR')
   ftp.dir()

我有一个错误: ConnectionRefusedError:[Errno 111]连接被拒绝

ftp是带有vsftpd的EC2

The ftp is an EC2 with vsftpd

pasv_enable=YES
pasv_min_port=1024
pasv_max_port=1048
pasv_address=IP
pasv_addr_resolve=YES

已经尝试过:

该代码可在具有和不具有TLS(托管于1and1,OVH ...)的其他FTP上工作

Already tried :

The code work on other FTP with and without TLS (hosted on 1and1, OVH...)

我在NodeJS中尝试了此脚本

I tried this script in NodeJS

const ftpClient = require('ftp-client');

const client = new ftpClient({
   host: "IP",
   port: 21,
   user: "My user", // defaults to "anonymous"
   password: "My password" // defaults to "@anonymous"
});

client.connect(() => {

  client.download('/MY_DIR/file','/tmp/file', (res) => {
        console.log(res)
  })
});

工作正常,所以我排除了防火墙问题

Works perfectly fine so I exclude a firewall problem

我尝试启用TLS

ssl_enable=YES
require_ssl_reuse=NO

然后sudo服务vsftpd重新启动

then sudo service vsftpd restart

并使用
FTP_TLS 而不是 FTP 但没有用

我也尝试通过设置

pasv_enable=NO

然后 sudo服务vsftpd重新启动

ftp.set_pasv(False)

也不起作用

推荐答案

解决方案

使用filezilla调试方法后,发现尽管我们在/etc/vsftpd.conf

pasv_adress=IP

此帖子对我们有帮助: https://www.centos.org/forums/viewtopic.php?t = 52408

this post helped us : https://www.centos.org/forums/viewtopic.php?t=52408

您必须发表评论

listen_ipv6=YES

并启用

listen=YES

/etc/vsftpd.conf

如果您无法访问FTP的vsftpd.conf,也可以覆盖ftplib的FTP类.

Also you can override the ftplib's class FTP if you can't access to vsftpd.conf of the FTP

class CustomFTP(ftplib.FTP):

    def makepasv(self):
        if self.af == socket.AF_INET:
            host, port = ftplib.parse227(self.sendcmd('PASV'))
        else:
            host, port = ftplib.parse229(self.sendcmd('EPSV'), self.sock.getpeername())

        if '0.0.0.0' == host:
            """ this ip will be unroutable, we copy Filezilla and return the host instead """
            host = self.host
        return host, port

如果发送'0.0.0.0',则强制上一个主机

to force the previous host if '0.0.0.0' is send

这篇关于Ftplib ConnectionRefusedError:[Errno 111]连接被拒绝(python 3.5)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆