C# FTP server inside docker container – issue with the connection

I'm not able to connect to docker container ftp server. Here is my docker file:

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

To run FTP server I create TcpListener the following way:

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

When I run it locally from the IDE I can connect to it using FileZilla. When I run it inside a container - no luck. What am I doing wrong?

FileZilla logs:

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

However I don't see anything in the application logs... Not sure what's happening



Read more here: https://stackoverflow.com/questions/66321903/c-sharp-ftp-server-inside-docker-container-issue-with-the-connection

Content Attribution

This content was originally published by Andrei at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: