[英]Ftplib ConnectionRefusedError: [Errno 111] Connection refused (python 3.5)
I have a script that should connect to a FTP我有一个应该连接到 FTP 的脚本
from ftplib import FTP
with FTP('IP') as ftp:
ftp.login(user='my user', passwd='my password')
ftp.cwd('/MY_DIR')
ftp.dir()
I have an error : ConnectionRefusedError: [Errno 111] Connection refused
我有一个错误:
ConnectionRefusedError: [Errno 111] Connection refused
The ftp is an EC2 with vsftpd ftp 是带有 vsftpd 的 EC2
pasv_enable=YES
pasv_min_port=1024
pasv_max_port=1048
pasv_address=IP
pasv_addr_resolve=YES
The code work on other FTP with and without TLS (hosted on 1and1, OVH...)该代码适用于其他带有和不带有 TLS 的 FTP(托管在 1and1、OVH...)
I tried this script in NodeJS我在 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工作得很好,所以我排除了防火墙问题
I have tried enable TLS我试过启用 TLS
ssl_enable=YES
require_ssl_reuse=NO
then sudo service vsftpd restart然后 sudo 服务 vsftpd 重启
and use并使用
FTP_TLS
instead of FTP
but did not work FTP_TLS
而不是FTP
但不起作用
Also I tried disable passive mode by setting我也尝试通过设置禁用被动模式
pasv_enable=NO
then sudo service vsftpd restart
然后
sudo service vsftpd restart
and ftp.set_pasv(False)
和
ftp.set_pasv(False)
didn't work either也没有用
After using filezilla to debug the method, turn out that our FTP returned 0.0.0.0 despite we defined in /etc/vsftpd.conf
使用filezilla调试该方法后,尽管我们在
/etc/vsftpd.conf
定义了我们的FTP返回0.0.0.0
pasv_adress=IP
this post helped us : https://www.centos.org/forums/viewtopic.php?t=52408这篇文章帮助了我们: https : //www.centos.org/forums/viewtopic.php?t=52408
You have to comment你必须评论
listen_ipv6=YES
and enable并启用
listen=YES
in /etc/vsftpd.conf
在
/etc/vsftpd.conf
Also you can override the ftplib's class FTP if you can't access to vsftpd.conf of the FTP如果您无法访问 FTP 的 vsftpd.conf,您也可以覆盖 ftplib 的类 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
to force the previous host if '0.0.0.0'
is send如果发送
'0.0.0.0'
则强制前一个主机
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.