我有一个应该连接到 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 的 FTP(托管在 1and1,OVH...)
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
I have tried enable TLS
ssl_enable=YES
require_ssl_reuse=NO
那么sudo service vsftpd 重启
then sudo service vsftpd restart
并使用FTP_TLS 而不是 FTP但没有工作
and use
FTP_TLS instead of FTP
but did not work
我也尝试通过设置禁用被动模式
Also I tried disable passive mode by setting
pasv_enable=NO
那么sudo service vsftpd restart
和ftp.set_pasv(False)
也没有用
使用filezilla调试该方法后,发现尽管我们在/etc/vsftpd.conf中定义了,我们的FTP还是返回0.0.0.0
pasv_adress=IP
这篇文章帮助了我们:https://www.centos.org/论坛/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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
为什么我不能插入 Python 列表?Why I cannot make an insert to Python list?(为什么我不能插入 Python 列表?)
在 DataFrame 的开头(最左端)插入一列Insert a column at the beginning (leftmost end) of a DataFrame(在 DataFrame 的开头(最左端)插入一列)
Python psycopg2 没有插入到 postgresql 表中Python psycopg2 not inserting into postgresql table(Python psycopg2 没有插入到 postgresql 表中)
list extend() 索引,不仅将列表元素插入到末尾list extend() to index, inserting list elements not only to the end(list extend() 索引,不仅将列表元素插入到末尾)
如何使用 list.insert 将 Python 中的元素添加到列表How to add element in Python to the end of list using list.insert?(如何使用 list.insert 将 Python 中的元素添加到列表末尾?)
TypeError:“浮动"对象不可下标TypeError: #39;float#39; object is not subscriptable(TypeError:“浮动对象不可下标)