Skip to content

Listing stopped working #1801

@skyflyer

Description

@skyflyer

First of all, thank you for a great library.

We're using FluentFTP to connect to an ftp server with TLS and a week or so ago that functionality broke with an error: Failed to get the EPSV port from: Entering Extended Passive Mode (|||46474)

While investigating the cause, I "fixed" this cause by explicitly setting the connection to use encrypted mode (client.Config.EncryptionMode = FtpEncryptionMode.Implicit;). The end result was that no files were listed even though they are present on the server. After turning on debug logging (attached below) I figured that might be due to issues with SSL resumes (issues #1738, #311).

I tried using GnuTlsStream, but that fails with System.DllNotFoundException: Unable to load shared library 'libdl.so.2' or one of its dependencies. (developing on a Mac).

End result: the program does not work on macOS (returns an empty listing on a macOS) but works when run with a docker image mcr.microsoft.com/dotnet/sdk:8.0 on the same machine.

Program code:

        using var client = new FtpClient(host, username, password);
        client.Config.LogToConsole = true;
        client.Config.EncryptionMode = FtpEncryptionMode.Implicit;
        client.Connect();
        Console.WriteLine("Connected. Is secure: {0}", client.IsConnected && client.IsEncrypted);
        var results = client.GetListing();
        Console.WriteLine("Retrieved {0} items", results.Length);
        foreach (var item in results) {
            Console.WriteLine("Found item: {0}", item.FullName);
        }

The log files (below) show that when the same program is ran in a docker container, the listing works; if the program is ran on macOS, the listing does not work and goes into retries. They're both using the same .NET SslStream as far as I can tell.

Any ideas?

Outputs for macOS and linux

macOS output

❯ dotnet run

# Connect(False)
Status:   FluentFTP 53.0.2.0(.NET 8.0) FtpClient
Status:   Connecting(sync) FtpClient.FtpSocketStream(control) IP #1 = ***:990
Status:   FTPS authentication successful, lib = .NET SslStream, cipher suite = Tls12 (Aes256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, DiffieHellman, 0) [590ms]
Status:   Waiting for a response
Response: 220 *** FTP site: Authorised logins only: IP address is recordered [739649.48d]
Command:  USER ***
Status:   Waiting for response to: USER ***
Response: 331 Password required for username [275ms]
Command:  PASS ***
Status:   Waiting for response to: PASS ***
Response: 230 Logged on [275ms]
Command:  PBSZ 0
Status:   Waiting for response to: PBSZ 0
Response: 200 PBSZ=0 [275ms]
Command:  PROT P
Status:   Waiting for response to: PROT P
Response: 200 Protection level set to P [275ms]
Command:  FEAT
Status:   Waiting for response to: FEAT
Response: 211-Features:
Response: MDTM
Response: REST STREAM
Response: SIZE
Response: MLST type*;size*;modify*;
Response: MLSD
Response: AUTH SSL
Response: AUTH TLS
Response: PROT
Response: PBSZ
Response: UTF8
Response: CLNT
Response: MFMT
Response: EPSV
Response: EPRT
Response: 211 End [276ms]
Status:   Text encoding: System.Text.UTF8Encoding+UTF8EncodingSealed
Command:  OPTS UTF8 ON
Status:   Waiting for response to: OPTS UTF8 ON
Response: 202 UTF8 mode is always enabled. No need to send this command. [276ms]
Command:  SYST
Status:   Waiting for response to: SYST
Response: 215 UNIX emulated by FileZilla [275ms]
Status:   Active ServerHandler is: None
Status:   Listing parser set to: Machine
Command:  PWD
Status:   Waiting for response to: PWD
Response: 257 "/" is current directory. [276ms]
Connected. Is secure: True

# GetListing(null, Auto)
Command:  TYPE I
Status:   Waiting for response to: TYPE I
Response: 200 Type set to I [275ms]

# OpenDataStream("MLSD /", 0)

# OpenPassiveDataStream(AutoPassive, "MLSD /", 0)
Command:  EPSV
Status:   Waiting for response to: EPSV
Response: 229 Entering Extended Passive Mode (|||46937|) [275ms]
Status:   Connecting(sync) FtpClient.FtpSocketStream(data) IP #1 = ***:46937
Command:  MLSD /
Status:   Waiting for response to: MLSD /
Response: 150 Opening data channel for directory listing of "/" [276ms]
Warning:  Retry GetListing once more due to unexpected EOF

# OpenDataStream("MLSD /", 0)

# OpenPassiveDataStream(AutoPassive, "MLSD /", 0)
Status:   Control connection has stale data(134) - prior to Execute("EPSV...")
Status:   The stale data was (length = 105): 
Stale:    450 TLS session of data connection has not resumed or the session does not match the control connection
Warning:  Reconnect needed due to stale data present on control connection (SslSessionLength: 27)
Status:   Disposing(sync) FtpClient.FtpSocketStream(control)
Status:   Command stashed: EPSV

# Connect(True)
Warning:  Reconnect (Count: 1)
Status:   FluentFTP 53.0.2.0(.NET 8.0) FtpClient
Status:   Connecting(sync) FtpClient.FtpSocketStream(control) IP #1 = ***:990
Status:   FTPS authentication successful, lib = .NET SslStream, cipher suite = Tls12 (Aes256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, DiffieHellman, 0) [575ms]
Status:   Waiting for a response
Response: 220 *** FTP site: Authorised logins only: IP address is recordered [1.707s]
Command:  USER ***
Status:   Waiting for response to: USER ***
Response: 331 Password required for username [277ms]
Command:  PASS ***
Status:   Waiting for response to: PASS ***
Response: 230 Logged on [277ms]
Command:  PBSZ 0
Status:   Waiting for response to: PBSZ 0
Response: 200 PBSZ=0 [277ms]
Command:  PROT P
Status:   Waiting for response to: PROT P
Response: 200 Protection level set to P [277ms]
Status:   Text encoding: System.Text.UTF8Encoding+UTF8EncodingSealed
Command:  OPTS UTF8 ON
Status:   Waiting for response to: OPTS UTF8 ON
Response: 202 UTF8 mode is always enabled. No need to send this command. [277ms]
Command:  SYST
Status:   Waiting for response to: SYST
Response: 215 UNIX emulated by FileZilla [277ms]
Status:   Active ServerHandler is: None
Status:   Listing parser set to: Machine
Command:  TYPE I
Status:   Waiting for response to: TYPE I
Response: 200 Type set to I [277ms]

# SetWorkingDirectory("/")
Command:  CWD /
Status:   Waiting for response to: CWD /
Response: 250 CWD successful. "/" is current directory. [277ms]

Status:   Executing stashed command

Command:  EPSV
Status:   Waiting for response to: EPSV
Response: 229 Entering Extended Passive Mode (|||46713|) [277ms]
Status:   Connecting(sync) FtpClient.FtpSocketStream(data) IP #1 = ***:46713
Command:  MLSD /
Status:   Waiting for response to: MLSD /
Response: 150 Opening data channel for directory listing of "/" [277ms]
Retrieved 0 items

# Dispose()
Status:   Disposing(sync) FtpClient

# Disconnect()
Status:   Control connection has stale data(134) - prior to Execute("QUIT...")
Status:   The stale data was (length = 105): 
Stale:    450 TLS session of data connection has not resumed or the session does not match the control connection
Warning:  Reconnect needed due to stale data present on control connection (SslSessionLength: 11)
Status:   Disposing(sync) FtpClient.FtpSocketStream(control) (redundant)
Status:   Not reconnecting for a QUIT command
Status:   Disposing(sync) FtpClient.FtpSocketStream(control) (redundant)

Linux (docker) output

# Connect(False)
Status:   FluentFTP 53.0.2.0(.NET 8.0) FtpClient
Status:   Connecting(sync) FtpClient.FtpSocketStream(control) IP #1 = ***:990
Status:   FTPS authentication successful, lib = .NET SslStream, cipher suite = Tls12 (Aes256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, DiffieHellman, 0) [662ms]
Status:   Waiting for a response
Response: 220 *** FTP site: Authorised logins only: IP address is recordered [739649.483d]
Command:  USER ***
Status:   Waiting for response to: USER ***
Response: 331 Password required for username [276ms]
Command:  PASS ***
Status:   Waiting for response to: PASS ***
Response: 230 Logged on [276ms]
Command:  PBSZ 0
Status:   Waiting for response to: PBSZ 0
Response: 200 PBSZ=0 [276ms]
Command:  PROT P
Status:   Waiting for response to: PROT P
Response: 200 Protection level set to P [276ms]
Command:  FEAT
Status:   Waiting for response to: FEAT
Response: 211-Features:
Response: MDTM
Response: REST STREAM
Response: SIZE
Response: MLST type*;size*;modify*;
Response: MLSD
Response: AUTH SSL
Response: AUTH TLS
Response: PROT
Response: PBSZ
Response: UTF8
Response: CLNT
Response: MFMT
Response: EPSV
Response: EPRT
Response: 211 End [279ms]
Status:   Text encoding: System.Text.UTF8Encoding+UTF8EncodingSealed
Command:  OPTS UTF8 ON
Status:   Waiting for response to: OPTS UTF8 ON
Response: 202 UTF8 mode is always enabled. No need to send this command. [277ms]
Command:  SYST
Status:   Waiting for response to: SYST
Response: 215 UNIX emulated by FileZilla [277ms]
Status:   Active ServerHandler is: None
Status:   Listing parser set to: Machine
Command:  PWD
Status:   Waiting for response to: PWD
Response: 257 "/" is current directory. [277ms]
Connected. Is secure: True

# GetListing(null, Auto)
Command:  TYPE I
Status:   Waiting for response to: TYPE I
Response: 200 Type set to I [277ms]

# OpenDataStream("MLSD /", 0)

# OpenPassiveDataStream(AutoPassive, "MLSD /", 0)
Command:  EPSV
Status:   Waiting for response to: EPSV
Response: 229 Entering Extended Passive Mode (|||46435|) [276ms]
Status:   Connecting(sync) FtpClient.FtpSocketStream(data) IP #1 = ***:46435
Command:  MLSD /
Status:   Waiting for response to: MLSD /
Response: 150 Opening data channel for directory listing of "/" [276ms]
Status:   FTPS authentication successful, lib = .NET SslStream, cipher suite = Tls12 (Aes256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, DiffieHellman, 0) [284ms]
+---------------------------------------+
Listing:  type=file;modify=20260112080105;size=5592; Delivered_20260112.csv
Listing:  type=file;modify=20260113080138;size=12570; Delivered_20260113.csv
Listing:  type=file;modify=20260114080055;size=2112; Delivered_20260114.csv
Listing:  type=file;modify=20260115080126;size=5486; Delivered_20260115.csv
Listing:  type=file;modify=20260116080205;size=6072; Delivered_20260116.csv
Listing:  type=file;modify=20260118080112;size=107; Delivered_20260118.csv
Listing:  type=file;modify=20260119080135;size=3067; Delivered_20260119.csv
Listing:  type=file;modify=20260120080226;size=8266; Delivered_20260120.csv
Listing:  type=file;modify=20260121080146;size=4674; Delivered_20260121.csv
Listing:  type=file;modify=20260122080049;size=4630; Delivered_20260122.csv
Listing:  type=file;modify=20260123080142;size=3716; Delivered_20260123.csv
Listing:  type=file;modify=20260127080026;size=4711; Delivered_20260127.csv
Listing:  type=file;modify=20260128080124;size=4826; Delivered_20260128.csv
Listing:  type=file;modify=20260129080105;size=5015; Delivered_20260129.csv
Listing:  type=file;modify=20260130080110;size=9973; Delivered_20260130.csv
Listing:  type=file;modify=20260131080144;size=294; Delivered_20260131.csv
Listing:  type=file;modify=20260202080100;size=2536; Delivered_20260202.csv
Listing:  type=file;modify=20260203080108;size=2890; Delivered_20260203.csv
-----------------------------------------
Status:   Disposing(sync) FtpClient.FtpSocketStream(data)

# CloseDataStream()
Status:   Waiting for response to: MLSD /
Response: 226 Successfully transferred "/" [848ms]
Status:   Disposing(sync) FtpClient.FtpSocketStream(data) (redundant)
Retrieved 18 items
Found item: /Delivered_20260112.csv
Found item: /Delivered_20260113.csv
Found item: /Delivered_20260114.csv
Found item: /Delivered_20260115.csv
Found item: /Delivered_20260116.csv
Found item: /Delivered_20260118.csv
Found item: /Delivered_20260119.csv
Found item: /Delivered_20260120.csv
Found item: /Delivered_20260121.csv
Found item: /Delivered_20260122.csv
Found item: /Delivered_20260123.csv
Found item: /Delivered_20260127.csv
Found item: /Delivered_20260128.csv
Found item: /Delivered_20260129.csv
Found item: /Delivered_20260130.csv
Found item: /Delivered_20260131.csv
Found item: /Delivered_20260202.csv
Found item: /Delivered_20260203.csv

# Dispose()
Status:   Disposing(sync) FtpClient

# Disconnect()
Command:  QUIT
Status:   Waiting for response to: QUIT
Response: 221 Goodbye [276ms]
Status:   Disposing(sync) FtpClient.FtpSocketStream(control)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions