FubarDevelopment / FtpServer

Portable FTP server written in .NET
http://fubardevelopment.github.io/FtpServer/
MIT License
482 stars 163 forks source link

Docker container PASV not able to connect #140

Open unknownguy opened 2 years ago

unknownguy commented 2 years ago

I am having troubles connecting to local docker container using PASV. However, this works fine using EPSV. Outside of the docker container everything works great!

I will add my config info and logs from both PASV and EPSV.

Current settings:

services
      .Configure<SimplePasvOptions>(
      opt =>
      {
          opt.PasvMinPort = 49152;
          opt.PasvMaxPort = 49153;
      })
      .Configure<FtpServerOptions>(opt =>
      {
          //opt.ServerAddress = "*";
          opt.Port = 21;
      });

Container active ports are: 21, 80, 443, 49152, 49153

They are active on both container and host ports.

PASV log:

info: FubarDev.FtpServer.FtpConnection[0]
      Connected from 172.17.0.1:42734
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      220 FTP Server Ready
dbug: FubarDev.FtpServer.FtpConnection[0]
      USER XXX
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      331 User XXX logged in, needs password
dbug: FubarDev.FtpServer.FtpConnection[0]
      PASS **************** (password omitted)
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      230 Password ok, FTP server ready
dbug: FubarDev.FtpServer.FtpConnection[0]
      TYPE A
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      200 ASCII transfer mode active.
dbug: FubarDev.FtpServer.FtpConnection[0]
      MODE S
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      200 Mode set to Stream.
dbug: FubarDev.FtpServer.FtpConnection[0]
      STRU F
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      200 Structure set to File.
dbug: FubarDev.FtpServer.FtpConnection[0]
      CWD /
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      250 Successful (/)
dbug: FubarDev.FtpServer.FtpConnection[0]
      CWD /
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      250 Successful (/)
dbug: FubarDev.FtpServer.FtpConnection[0]
      PASV 
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      227 Entering Passive Mode (172,17,0,2,192,0).
dbug: FubarDev.FtpServer.FtpConnection[0]
      LIST 
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      150 Opening data connection.
warn: FubarDev.FtpServer.ServerCommandHandlers.DataConnectionServerCommandHandler[0]
      Could not open data connection: The operation has timed out.
System.TimeoutException: The operation has timed out.
   at FubarDev.FtpServer.DataConnection.PassiveDataConnectionFeatureFactory.PassiveDataConnectionFeature.GetDataConnectionAsync(TimeSpan timeout, CancellationToken cancellationToken)
   at FubarDev.FtpServer.FtpConnection.OpenDataConnectionAsync(Nullable`1 timeout, CancellationToken cancellationToken)
   at FubarDev.FtpServer.ServerCommandHandlers.DataConnectionServerCommandHandler.ExecuteAsync(DataConnectionServerCommand command, CancellationToken cancellationToken)
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      425 Could not open data connection
dbug: FubarDev.FtpServer.FtpConnection[0]
      Quit 
dbug: FubarDev.FtpServer.FtpConnection[0]
      Stopped sending responses
dbug: FubarDev.FtpServer.FtpConnection[0]
      Stopped reading commands
warn: FubarDev.FtpServer.Commands.DefaultFtpCommandDispatcher[0]
      Sending the response cancelled: 426 Connection closed; transfer aborted.
info: FubarDev.FtpServer.FtpConnection[0]
      Connection closed

EPSV log:

info: FubarDev.FtpServer.FtpConnection[0]
      Connected from 172.17.0.1:42738
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      220 FTP Server Ready
dbug: FubarDev.FtpServer.FtpConnection[0]
      AUTH TLS
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      500 Syntax error, command unrecognized.
dbug: FubarDev.FtpServer.FtpConnection[0]
      AUTH SSL
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      500 Syntax error, command unrecognized.
dbug: FubarDev.FtpServer.FtpConnection[0]
      USER XXX
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      331 User XXX logged in, needs password
dbug: FubarDev.FtpServer.FtpConnection[0]
      PASS **************** (password omitted)
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      230 Password ok, FTP server ready
dbug: FubarDev.FtpServer.FtpConnection[0]
      SYST 
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      215 UNIX Type: A
dbug: FubarDev.FtpServer.FtpConnection[0]
      FEAT 
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      211-Extensions supported:
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
       EPRT
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
       EPSV
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
       HOST
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
       LANG en*
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
       MDTM
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
       MFCT
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
       MFF modify;create;
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
       MFMT
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
       MLST type*;size*;perm*;modify*;create*;
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
       REST STREAM
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
       SITE BLST
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
       SIZE
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
       UTF8
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      211 END
dbug: FubarDev.FtpServer.FtpConnection[0]
      OPTS UTF8 ON
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      200 Command okay.
dbug: FubarDev.FtpServer.FtpConnection[0]
      CWD /
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      250 Successful (/)
dbug: FubarDev.FtpServer.FtpConnection[0]
      PWD 
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      257 "/"
dbug: FubarDev.FtpServer.FtpConnection[0]
      TYPE I
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      200 Binary transfer mode active.
dbug: FubarDev.FtpServer.FtpConnection[0]
      EPSV 
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      229 Entering Extended Passive Mode (|||49152|).
dbug: FubarDev.FtpServer.FtpConnection[0]
      MLSD 
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      150 Opening data connection.
dbug: FubarDev.FtpServer.DataConnection.PassiveDataConnectionFeatureFactory[0]
      Data connection accepted from 172.17.0.1:58222
trce: FubarDev.FtpServer.CommandHandlers.MlstCommandHandler[0]
      perm=el;type=cdir; .
trce: FubarDev.FtpServer.CommandHandlers.MlstCommandHandler[0]
      perm=el;type=dir; fonts
trce: FubarDev.FtpServer.CommandHandlers.MlstCommandHandler[0]
      perm=el;type=dir; images
trce: FubarDev.FtpServer.CommandHandlers.MlstCommandHandler[0]
      perm=el;type=dir; scripts
trce: FubarDev.FtpServer.CommandHandlers.MlstCommandHandler[0]
      perm=el;type=dir; styles
trce: FubarDev.FtpServer.CommandHandlers.MlstCommandHandler[0]
      perm=el;type=dir; templateItems
trce: FubarDev.FtpServer.CommandHandlers.MlstCommandHandler[0]
      perm=el;type=dir; templates
trce: FubarDev.FtpServer.CommandHandlers.MlstCommandHandler[0]
      perm=r;size=0;type=file; FullMasterPage.html
trce: FubarDev.FtpServer.CommandHandlers.MlstCommandHandler[0]
      perm=r;size=0;type=file; settings.json
dbug: FubarDev.FtpServer.ServerCommandHandlers.SendResponseServerCommandHandler[0]
      226 Closing data connection.

Any thoughts?

fubar-coder commented 2 years ago

No idea. It just looks like the client not being able to connect to the passively opened port. This might have a multitude of causes and is difficult to diagnose from a distance.

unknownguy commented 2 years ago

For what is worth, the docker image is on linux.

vudzero commented 1 year ago

I think you must specify opt.ServerAddres to the IP address used by your client to connect to your ftp server. Otherwise the local ip address of the docker container will be sent back to your client, which is not what you want.

vudzero commented 1 year ago

I made it work by setting the PublicAddress of the SimplePasvOptions to the ip address of my server