簡體   English   中英

docker 容器內的 C# FTP 服務器 - 連接問題

[英]C# FTP server inside docker container - issue with the connection

我無法連接到 docker 容器 ftp 服務器。 這是我的 docker 文件:

FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine AS build
WORKDIR /app
COPY . ./
RUN dotnet publish MD.Ftp.Server -c Release -o out -r linux-x64 
FROM mcr.microsoft.com/dotnet/runtime:5.0
WORKDIR /app
COPY --from=build /app/out .
ENTRYPOINT ["dotnet", "MD.Ftp.Server.dll"]
EXPOSE 6001/tcp

要運行 FTP 服務器,我按以下方式創建 TcpListener:

tcpListener = new TcpListener(new IPEndPoint(IPAddress.Any, settings.Port));

當我從 IDE 在本地運行它時,我可以使用 FileZilla 連接到它。 當我在容器內運行它時 - 不走運。 我究竟做錯了什么?

FileZilla 日志:

Status:         Disconnected from server
Status:         Connecting to 127.0.0.1:6001...
Status:         Connection established, waiting for welcome message...
Status:         Plain FTP is insecure. Please switch to FTP over TLS.
Status:         Logged in
Status:         Retrieving directory listing...
Command:    PWD
Response:   257 "/"
Command:    TYPE I
Response:   200 In IMAGE type
Command:    PASV
Response:   227 Enter Passive Mode (172,17,0,2,234,142)
Command:    LIST
Response:   150 File is Ok, about to open connection.
Error:          Connection timed out after 20 seconds of inactivity
Error:          Failed to retrieve directory listing
Status:         Disconnected from server
Status:         Connecting to 127.0.0.1:6001...
Status:         Connection established, waiting for welcome message...
Status:         Plain FTP is insecure. Please switch to FTP over TLS.
Status:         Logged in
Status:         Retrieving directory listing...
Command:    PWD
Response:   257 "/"
Command:    TYPE I
Response:   200 In IMAGE type
Command:    PASV
Response:   227 Enter Passive Mode (172,17,0,2,234,143)
Command:    LIST
Response:   150 File is Ok, about to open connection.
Error:          Connection timed out after 20 seconds of inactivity
Error:          Failed to retrieve directory listing

但是我在應用程序日志中看不到任何內容...不確定發生了什么

你如何運行你的容器? 您應該發布您的端口以及公開。 Expose 是一個 docker-inside 概念,而 publish 是 docker 之一。 我是說:

docker run -d -p 6001:6001 YOUR_IMAGE_NAME

您可能知道,FTP 協議有兩種類型,ACTIVE 和 PASSIVE。 您應該打開至少 10 個從 X 到 Y(范圍)的端口,讓您的客戶端使用默認的 FTP 命令訪問您的 FTP 服務器。 我強烈推薦你看這篇文章https://www.jscape.com/blog/bid/80512/active-vs-passive-ftp-simplified

嗨有同樣的問題,我想出了為什么但不知道如何解決它。

您有兩個連接,一個是控制連接,另一個是您的數據連接,顯然它們需要具有相同的 IP。

所以現在我不知道你的代碼,但基於 output,你的 controlconnection 得到了 IP 127.0.0.1,但你的 dataconnection 得到了 ZA12A3079E14CED47B2069BA52B172 的容器。 並且由於兩個連接不同 IP 服務器關閉連接。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM