无法在 CentOS 7 上使用 FTP 被动模式(在 Docker 容器中运行)

无法在 CentOS 7 上使用 FTP 被动模式(在 Docker 容器中运行)

我有一台 CentOS 7 机器,在 Docker 容器内运行。

我正在开发一个应用程序,它必须连接到 FTP 服务器并下载一些文件 - 为此,我需要将我的 FTP 连接设置为被动模式。不幸的是,这台机器似乎根本无法使用 FTP 被动模式。无论我尝试使用什么客户端,我总是会得到相同的错误:

ftp> open ftp
Connected to ftp (172.18.0.8).
220 (vsFTPd 3.0.3)
Name (ftp:root): admin
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (10,105,125,200,185,104).
ftp: connect: No route to host

以下是来自 FTP 服务器的日志:

Tue Jun 19 12:36:32 2018 [pid 20820] CONNECT: Client "172.18.0.7"
Tue Jun 19 12:36:32 2018 [pid 20820] FTP response: Client "172.18.0.7", "220 (vsFTPd 3.0.3)"
Tue Jun 19 12:36:34 2018 [pid 20820] FTP command: Client "172.18.0.7", "USER admin"
Tue Jun 19 12:36:34 2018 [pid 20820] [admin] FTP response: Client "172.18.0.7", "331 Please specify the password."
Tue Jun 19 12:36:38 2018 [pid 20820] [admin] FTP command: Client "172.18.0.7", "PASS <password>"
Tue Jun 19 12:36:38 2018 [pid 20819] [admin] OK LOGIN: Client "172.18.0.7"
Tue Jun 19 12:36:38 2018 [pid 20821] [admin] FTP response: Client "172.18.0.7", "230 Login successful."
Tue Jun 19 12:36:38 2018 [pid 20821] [admin] FTP command: Client "172.18.0.7", "SYST"
Tue Jun 19 12:36:38 2018 [pid 20821] [admin] FTP response: Client "172.18.0.7", "215 UNIX Type: L8"
Tue Jun 19 12:36:43 2018 [pid 20821] [admin] FTP command: Client "172.18.0.7", "PASV"
Tue Jun 19 12:36:43 2018 [pid 20821] [admin] FTP response: Client "172.18.0.7", "227 Entering Passive Mode (10,105,125,200,185,104)." 

使用相同的凭据、主机名(10.105.125.200 是我本地网络内的地址)和端口(21),我在其他运行 Docker 的机器上使用被动模式没有任何问题。例如,在 Debian 机器上,不会出现此问题。

我尝试了以下修复方法:https://linuxconfig.org/rhel7-ftp-server-error-ftp-connect-no-route-to-host-solution但由于该机器在 Docker 上运行,它不具备原始机器的全部功能(至少不是开箱即用的)-> 例如,我无法运行 iptables。

我还发现一些建议,也许 CentOS 防火墙阻止了某些东西 - 但是,机器在 Docker 内部的问题也阻止了我,因为我无法使用像 systemctl 这样的基本程序。

相关内容