Py学习  »  docker

连接到在docker中运行的ftp服务器

smaqsood • 4 年前 • 181 次点击  

我在windows主机上的Docker容器中运行ftp服务器。我已经为SSH和FTP映射了(-p)端口22和21。我无法从主机成功地通过FTP连接到FTP服务器。看起来ftp客户端(可爱的ftp)使用随机端口列出目录和文件,这是连接断开的地方。使用凭据查看日志连接会成功,但在以后列出目录时会失败并断开连接。我试图找出如何设置ftps服务器在Docker容器,其中ftp客户端使用随机端口进行成功的连接。仅供参考,我试过端口和PASIVE连接类型,但都不起作用。这是我的cuteftp连接日志:

*** CuteFTP 8.0 - build Aug 22 2006 ***

STATUS:>    [2/13/2019 11:22:56 AM] Getting listing ""...
STATUS:>    [2/13/2019 11:22:56 AM] Resolving host name localhost...
STATUS:>    [2/13/2019 11:22:56 AM] Host name localhost resolved: ip = 127.0.0.1.
STATUS:>    [2/13/2019 11:22:56 AM] Connecting to FTP server... localhost:2121 (ip = 127.0.0.1)...
STATUS:>    [2/13/2019 11:22:56 AM] Socket connected. Waiting for welcome message...
        [2/13/2019 11:22:56 AM] 220 (vsFTPd 3.0.3)
STATUS:>    [2/13/2019 11:22:56 AM] Connected. Authenticating...
COMMAND:>   [2/13/2019 11:22:56 AM] USER ftpuser
        [2/13/2019 11:22:56 AM] 331 Please specify the password.
COMMAND:>   [2/13/2019 11:22:56 AM] PASS *****
        [2/13/2019 11:22:56 AM] 230 Login successful.
STATUS:>    [2/13/2019 11:22:56 AM] Login successful.
COMMAND:>   [2/13/2019 11:22:56 AM] PWD
        [2/13/2019 11:22:56 AM] 257 "/" is the current directory
STATUS:>    [2/13/2019 11:22:56 AM] Home directory: /
COMMAND:>   [2/13/2019 11:22:56 AM] FEAT
        [2/13/2019 11:22:56 AM] Informational Message Only:
        211-Features:
         EPRT
         EPSV
         MDTM
         PASV
         REST STREAM
         SIZE
         TVFS
        211 End
STATUS:>    [2/13/2019 11:22:56 AM] This site supports features.
STATUS:>    [2/13/2019 11:22:56 AM] This site supports SIZE.
STATUS:>    [2/13/2019 11:22:56 AM] This site can resume broken downloads.
COMMAND:>   [2/13/2019 11:22:56 AM] REST 0
        [2/13/2019 11:22:56 AM] 350 Restart position accepted (0).
COMMAND:>   [2/13/2019 11:22:56 AM] PASV
        [2/13/2019 11:22:56 AM] 227 Entering Passive Mode (172,17,0,2,202,168).
STATUS:>    [2/13/2019 11:22:56 AM] Substituting received PASV address 172.17.0.2 to server address 127.0.0.1.
COMMAND:>   [2/13/2019 11:22:56 AM] LIST
STATUS:>    [2/13/2019 11:22:56 AM] Connecting FTP data socket... 127.0.0.1:51880...
ERROR:>     [2/13/2019 11:22:57 AM] The remote host actively refused the attempt to connect to it.
        1) Verify that the destination server name or IP address is correct
        2) Verify that the connection port number is correct (under Site Settings | Type tab).
        3) The remote server may be temporarily or permanently inaccessible (try again later).
        4) Verify that you have chosen the right protocol (SSH2, SSL, FTP, etc.) and have setup all required options for that protocol.
        5) Verify that the destination IP address and port numbers are correct.
        6) The remote server may be refusing multiple connections from the same client. Try using only one connection thread when connecting to this particular server (Site Settings | Options).
        7) Try pinging the address.
        8) If you are using a router, verify the router is up and running (check by pinging it and then ping an address outside of the router).
        9) Do a traceroute to the destination to verify all routers along the connection path are operational.
        10) Verify that your subnet mask is setup properly.
        11) Verify that your local software or hardware firewall is not blocking outbound connections originating from CuteFTP.
        12) Verify that your anti-virus software is not at fault (try disabling it).
ERROR:>     [2/13/2019 11:22:57 AM] PASV failed, trying PORT.
STATUS:>    [2/13/2019 11:22:57 AM] Waiting 0 seconds...
STATUS:>    [2/13/2019 11:22:57 AM] Getting listing "/"...
STATUS:>    [2/13/2019 11:22:57 AM] Resolving host name localhost...
STATUS:>    [2/13/2019 11:22:57 AM] Host name localhost resolved: ip = 127.0.0.1.
STATUS:>    [2/13/2019 11:22:57 AM] Connecting to FTP server... localhost:2121 (ip = 127.0.0.1)...
STATUS:>    [2/13/2019 11:22:57 AM] Socket connected. Waiting for welcome message...
        [2/13/2019 11:22:57 AM] 220 (vsFTPd 3.0.3)
STATUS:>    [2/13/2019 11:22:57 AM] Connected. Authenticating...
COMMAND:>   [2/13/2019 11:22:57 AM] USER ftpuser
        [2/13/2019 11:22:57 AM] 331 Please specify the password.
COMMAND:>   [2/13/2019 11:22:57 AM] PASS *****
        [2/13/2019 11:22:57 AM] 230 Login successful.
STATUS:>    [2/13/2019 11:22:57 AM] Login successful.
COMMAND:>   [2/13/2019 11:22:57 AM] PWD
        [2/13/2019 11:22:57 AM] 257 "/" is the current directory
STATUS:>    [2/13/2019 11:22:57 AM] Home directory: /
STATUS:>    [2/13/2019 11:22:57 AM] This site supports features.
STATUS:>    [2/13/2019 11:22:57 AM] This site supports SIZE.
STATUS:>    [2/13/2019 11:22:57 AM] This site can resume broken downloads.
COMMAND:>   [2/13/2019 11:22:57 AM] REST 0
        [2/13/2019 11:22:57 AM] 350 Restart position accepted (0).
COMMAND:>   [2/13/2019 11:22:57 AM] PORT 127,0,0,1,205,112
        [2/13/2019 11:22:57 AM] 500 Illegal PORT command.
ERROR:>     [2/13/2019 11:22:57 AM] Syntax error: command unrecognized.
ERROR:>     [2/13/2019 11:22:57 AM] Failed to establish data socket.

我运行以下命令来启动ubuntu容器

docker -dit --name ubuntu -p 80:80 -p 22:22 -p 21:21 ubuntu
docker exec -it ubuntu bash
apt update
apt install vfstpd

使用所需的更改编辑vsftpd.conf。基于cuteftp日志,我得到了成功的连接,但目录和文件没有列出,因为cuteftp正在使用会话的随机端口来显示文件和目录。我只有端口80,22和21映射到容器。

没有用例。我对docker还不太熟悉,只是在玩和学习。我想运行ubuntu容器,然后在上面安装LAMP。我成功地安装了LAMP,但随后需要FTP服务器将文件上传到html文件夹以测试站点。这只是学习。我知道我可以找到已经安装了灯的docker图像,但这不是学习。我确实对运行ubuntu容器有疑问,我相信我已经单独问过了(单独的问题),并等待有人回答。

根据你的建议我试过了

 docker run -dit --name ubuntu --network host ubuntu

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/54635
 
181 次点击