GetListing returns an incomplete listing without an error when the data connection is reset (control reply 226)
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 45/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- csharp
- Área
- networking
Línea de trabajo
The silent catch is in FluentFTP/Client/AsyncClient/GetListing.cs (around lines 410-434) and FluentFTP/Client/SyncClient/GetListing.cs (around lines 283-307), where the data-stream IOException is dropped and the partial lines are returned. Run the repro's Program.cs with dotnet run; it uses a scripted server on 127.0.0.1 and exits 1 while the defect is present. Done when the reset runs either throw or return all 4 entries for both clients, and the normal-close runs still return 4 entries.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
FTP Server OS: n/a (scripted test server on 127.0.0.1, included below)
FTP Server Type: n/a (scripted test server)
Client Computer OS: Windows 11 x64
FluentFTP Version: 55.1.0 (NuGet); also master at cdc4c1f (built from source)
Framework: .NET 8 (8.0.34) and .NET 11 (11.0.0)
What happens
The data connection of a directory listing ends with a TCP reset (RST) after part of the listing was sent, and the control connection replies 226. GetListing then returns only what it read before the reset and does not throw:
FtpClient.GetListing("/")returns 2 of 4 entries.AsyncFtpClient.GetListing("/")returns 0 of 4 entries.
The caller cannot tell the result is incomplete. Inside GetListing the reset is thrown as an IOException (inner SocketException, SocketErrorCode = ConnectionReset; visible with dotnet run -- --log), and it does not reach the caller. Reading the source, it ends in this catch block, which drops the exception and returns the lines read so far: AsyncClient/GetListing.cs#L410-L434, SyncClient/GetListing.cs#L283-L307. The control connection is still connected, so the retry/throw added for #1080 does not apply.
With the same server and a normal end of the data connection (FIN), both clients return all 4 entries.
Expected
GetListing reports the failed transfer (throws, or retries and returns the complete listing). It should not return a partial listing as if it were complete.
Minimal repro
Two files. The program starts a small scripted FTP server on 127.0.0.1 (EPSV + LIST), so no external server is needed. For each client it lists once with a normal end of the data connection (control run) and once with an RST after 2 of the 4 lines, with 226 on the control connection before the RST. Exit code 1 means the incomplete listing came back without an error.
FluentFtpListingReset.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentFTP" Version="55.1.0" />
</ItemGroup>
</Project>
Program.cs
// Minimal repro: FluentFTP GetListing returns an incomplete listing and reports success when the DATA
// connection is reset (TCP RST) in the middle of the transfer while the control connection replies
// "226 transfer complete". A tiny scripted FTP server on 127.0.0.1 plays the server side.
//
// dotnet run -> prints one line per scenario; exit code 1 = defect reproduced
// dotnet run -- --log -> the same with FluentFTP's verbose log (Config.LogToConsole) for the reset runs
// and every IOException thrown inside the process (first-chance)
using System.Net;
using System.Net.Sockets;
using System.Text;
using FluentFTP;
string[] listing =
[
"-rw-r--r-- 1 owner group 10 Jan 01 2026 a.txt",
"-rw-r--r-- 1 owner group 10 Jan 01 2026 b.txt",
"-rw-r--r-- 1 owner group 10 Jan 01 2026 c.txt",
"-rw-r--r-- 1 owner group 10 Jan 01 2026 d.txt",
];
var log = args.Contains("--log");
if (log)
AppDomain.CurrentDomain.FirstChanceException += (_, e) =>
{
if (e.Exception is IOException { InnerException: SocketException socket })
Console.WriteLine($"[first-chance] IOException, inner SocketException {socket.SocketErrorCode}");
};
var defect = false;
var stubBroken = false;
foreach (var async in new[] { false, true })
{
var client = async ? "AsyncFtpClient" : "FtpClient ";
// control: the data connection is closed normally (FIN) after the whole listing
var (count, error) = await ListAsync(async, StartServer(listing, resetAfterLines: null), log: false);
Console.WriteLine($"{client} data connection closed normally -> {Describe(count, error)}");
stubBroken |= count != listing.Length;
// defect: the data connection is reset (RST) after 2 of 4 lines; the control connection says 226
(count, error) = await ListAsync(async, StartServer(listing, resetAfterLines: 2), log);
var silent = error is null && count < listing.Length;
Console.WriteLine($"{client} data connection reset after 2 of 4 lines -> {Describe(count, error)}{(silent ? " <-- incomplete listing, no error" : "")}");
defect |= silent;
}
return stubBroken ? 2 : defect ? 1 : 0;
static string Describe(int count, Exception? error) =>
error is null ? $"{count} entries, no exception" : $"{error.GetType().Name}: {error.Message}";
static async Task<(int Count, Exception? Error)> ListAsync(bool async, int port, bool log)
{
try
{
if (async)
{
await using var ftp = new AsyncFtpClient("127.0.0.1", "user", "pass", port);
ftp.Config.LogToConsole = log;
await ftp.Connect();
return ((await ftp.GetListing("/")).Length, null);
}
else
{
using var ftp = new FtpClient("127.0.0.1", "user", "pass", port);
ftp.Config.LogToConsole = log;
ftp.Connect();
return (ftp.GetListing("/").Length, null);
}
}
catch (Exception ex)
{
return (-1, ex);
}
}
// Scripted single-session FTP server. EPSV for the data connection, LIST for the listing.
static int StartServer(string[] listing, int? resetAfterLines)
{
var control = new TcpListener(IPAddress.Loopback, 0);
control.Start();
new Thread(() => Serve(control, listing, resetAfterLines)) { IsBackground = true }.Start();
return ((IPEndPoint)control.LocalEndpoint).Port;
}
static void Serve(TcpListener control, string[] listing, int? resetAfterLines)
{
using var session = control.AcceptTcpClient();
control.Stop();
var stream = session.GetStream();
var reader = new StreamReader(stream, Encoding.ASCII);
void Reply(string text) => stream.Write(Encoding.ASCII.GetBytes(text + "\r\n"));
TcpListener? passive = null;
Reply("220 ready");
while (reader.ReadLine() is { } command)
{
switch (command.Split(' ')[0].ToUpperInvariant())
{
case "USER": Reply("331 password required"); break;
case "PASS": Reply("230 logged in"); break;
case "SYST": Reply("215 UNIX Type: L8"); break;
case "PWD": Reply("257 \"/\" is the current directory"); break;
case "TYPE": Reply("200 type set"); break;
case "EPSV":
passive = new TcpListener(IPAddress.Loopback, 0);
passive.Start();
Reply($"229 Entering Extended Passive Mode (|||{((IPEndPoint)passive.LocalEndpoint).Port}|)");
break;
case "LIST":
using (var data = passive!.AcceptSocket())
{
passive.Stop();
Reply("150 opening data connection");
var lines = resetAfterLines is { } n ? listing.Take(n) : listing;
data.Send(Encoding.ASCII.GetBytes(string.Concat(lines.Select(l => l + "\r\n"))));
if (resetAfterLines is null)
{
data.Shutdown(SocketShutdown.Both); // normal end of the transfer (FIN) ...
data.Close();
Reply("226 transfer complete"); // ... then 226
}
else
{
Reply("226 transfer complete"); // 226 on the control connection ...
data.LingerState = new LingerOption(true, 0);
data.Close(); // ... and the data connection ends with RST
}
}
break;
case "QUIT": Reply("221 bye"); return;
default: Reply("502 not implemented"); break;
}
}
}
Output
The same output on 20 of 20 runs each with .NET 8 / FluentFTP 55.1.0, .NET 11 / FluentFTP 55.1.0, and .NET 8 / master cdc4c1f:
FtpClient data connection closed normally -> 4 entries, no exception
FtpClient data connection reset after 2 of 4 lines -> 2 entries, no exception <-- incomplete listing, no error
AsyncFtpClient data connection closed normally -> 4 entries, no exception
AsyncFtpClient data connection reset after 2 of 4 lines -> 0 entries, no exception <-- incomplete listing, no error
Logs :
dotnet run -- --log, FtpClient reset run (the [first-chance] line is printed by the repro, not by FluentFTP):
# Connect(False)
Status: FluentFTP 55.1.0.0(Windows/.NET 8.0) FtpClient
Status: Connecting(sync) FtpClient.FtpSocketStream(control) IP #1 = ***:57887
Status: Waiting for a response
Response: 220 ready [739931,447d]
Command: USER ***
Status: Waiting for response to: USER ***
Response: 331 password required [<1ms]
Command: PASS ***
Status: Waiting for response to: PASS ***
Response: 230 logged in [<1ms]
Command: FEAT
Status: Waiting for response to: FEAT
Response: 502 not implemented [<1ms]
Status: Text encoding: System.Text.ASCIIEncoding+ASCIIEncodingSealed
Command: SYST
Status: Waiting for response to: SYST
Response: 215 UNIX Type: L8 [<1ms]
Status: Active ServerHandler is: None
Status: Listing parser set to: Unix
Command: PWD
Status: Waiting for response to: PWD
Response: 257 "/" is the current directory [<1ms]
# GetListing("/", Auto)
Command: TYPE I
Status: Waiting for response to: TYPE I
Response: 200 type set [<1ms]
# OpenDataStream("LIST /", 0)
# OpenPassiveDataStream(AutoPassive, "LIST /", 0)
Command: EPSV
Status: Waiting for response to: EPSV
Response: 229 Entering Extended Passive Mode (|||57889|) [<1ms]
Status: Connecting(sync) FtpClient.FtpSocketStream(data) IP #1 = ***:57889
Command: LIST /
Status: Waiting for response to: LIST /
Response: 150 opening data connection [<1ms]
+---------------------------------------+
Listing: -rw-r--r-- 1 owner group 10 Jan 01 2026 a.txt
Listing: -rw-r--r-- 1 owner group 10 Jan 01 2026 b.txt
[first-chance] IOException, inner SocketException ConnectionReset
Status: Disposing(sync) FtpClient.FtpSocketStream(data)
# CloseDataStream()
Status: Waiting for response to: LIST /
Response: 226 transfer complete [5ms]
Status: Disposing(sync) FtpClient.FtpSocketStream(data) (redundant)
Status: Confirmed format Unix
# Dispose()
Status: Disposing(sync) FtpClient
# Disconnect()
Command: QUIT
Status: Waiting for response to: QUIT
Response: 221 bye [<1ms]
Status: Disposing(sync) FtpClient.FtpSocketStream(control)
Related
- #1080:
GetListingreturned an empty array when the control connection was lost during the listing. The fix retries once or throws whenm_stream.IsConnectedis false. In this repro only the data connection is reset; the control connection stays connected and the226is read normally.
- Lenguaje dominante
- C#
- Estrellas
- 3.4k
- Forks
- 684
- Merge medio
- 3 d 11 h
- PR fusionados (30 d)
- 4
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de robinrodricks/FluentFTP
-
enhancement help wanted major
Dificultad 5/5 Más de una semana Aptitud para principiantes 15/100
robinrodricks/FluentFTP#1889 · 3 comentarios ·
-
.NET maintenance response requested
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
robinrodricks/FluentFTP#1886 · 7 comentarios ·
-
bug fixed Pending next release pureftpd-server workaround
Dificultad 3/5 1-2 días Aptitud para principiantes 57/100
robinrodricks/FluentFTP#1878 · 12 comentarios ·
-
incorrect usage
Dificultad 3/5 1-2 días Aptitud para principiantes 50/100
robinrodricks/FluentFTP#1859 · 4 comentarios ·
-
faq incorrect usage question security
Dificultad 2/5 1-3 horas Aptitud para principiantes 55/100
robinrodricks/FluentFTP#1836 · 2 comentarios ·
Todos los issues de robinrodricks/FluentFTP
Issues similares
-
agentic-workflows
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
dotnet/maui#40788 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
good first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 92/100
erkamyaman/rust-anything#943 ·
Los mantenedores suelen responder en 1 día
-
priority:P2
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
SixLabors/ImageSharp.Drawing#438 · 1 comentario ·
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100