Skip to content

FTP/SSL upload and download no longer work with .NET 10 #123135

@HeinziAT

Description

@HeinziAT

Description

The following repro code works corrently when compiled with TargetFramework net9.0, but fails with an exception when compiled with TargetFramework net10.0.

Reproduction Steps

This repro example requires an FTP server with "explicit mode" SSL. Uploading without SSL works fine even with .NET 10.

using System;
using System.Net;
using System.Text;

// Replace with an FTPS server that you have access to.
string url = "ftp://user:password@server.example/a.txt";

FtpWebRequest request = (FtpWebRequest)WebRequest.Create(url);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.EnableSsl = true;

byte[] data = Encoding.UTF8.GetBytes("Lorem ipsum");

using (var stream = request.GetRequestStream())
{
    stream.Write(data, 0, data.Length);
}

using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
{
    Console.WriteLine((int)response.StatusCode);
}

Expected behavior

The program uploads the file and prints "226" (a success status code). This is what happens when compiled with net9.0.

Actual behavior

This exception occurs at the closing brace of the first using block (when the request stream is disposed):

Unhandled exception. System.Net.WebException: The underlying connection was closed: The server committed a protocol violation
   at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
   at System.Net.CommandStream.Abort(Exception e)
   at System.Net.CommandStream.CheckContinuePipeline()
   at System.Net.FtpDataStream.System.Net.ICloseEx.CloseEx(CloseExState closeState)
   at System.Net.FtpDataStream.Dispose(Boolean disposing)
   at System.IO.Stream.Close()
   at Program.<Main>$(String[] args) in C:\[redacted]\Program.cs:line 17
   at Program.<Main>$(String[] args) in C:\[redacted]\Program.cs:line 6

Regression?

This works in .net 9, but not in .net 10.

Known Workarounds

Disable SSL.

(To state the obvious, in case inexperienced developers happen to read this: Don't do this, this will send your password in plain text over the Internet.)

Configuration

  • Client: Windows 11
  • Server: ProFTPD

Other information

I am aware that FtpWebRequest should not be used for new development. This, however, is a minimal example based on a legacy application breaking during the .net 9->10 upgrade.

Edit: Download is also broken, see the discussion below for a repro example.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions