2

According to https://learn.microsoft.com/en-us/dotnet/api/system.net.ftpwebrequest.proxy?view=netcore-3.1 FtpWebRequest does not support proxy with .NET Core. Is there an alternative?

I need to access a FTP file via some squid proxy (i.e. FTP over HTTP) with proxy authentication (NTLM).

This is example code:

FtpWebRequest request = (FtpWebRequest) WebRequest.Create("ftp://ftp.ubuntu.com/");
var proxy = new WebProxy("my.squid.host", 8080);
proxy.Credentials = new NetworkCredential("squid_user", "squid_pass");
request.Proxy = proxy;
WebResponse response = request.GetResponse();

var result = new StreamReader(response.GetResponseStream()).ReadToEnd();
Console.WriteLine(result);

If you replace squid host/user/pass in this code with yours, you will see this works fine with this csproj file:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net472</TargetFramework>
      </PropertyGroup>
</Project>

But it no longer works with .NET Core:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>netcoreapp3.1</TargetFramework>
      </PropertyGroup>
</Project>
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
stb
  • 772
  • 5
  • 15

1 Answers1

3

There's no other FTP implementation in .NET framework than FtpWebRequest. And FtpWebRequest itself is deprecated and won't be improved. You have to use a 3rd party FTP client library.

See:


In general, you can use FluentFTP or my WinSCP .NET assembly.

Though neither supports NTLM authentication (a requirement you have added later). I'm not aware of any other free widely used .NET FTP library.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • Thanks for the fast and helpful answer (and BTW thanks for WinSCP). FluentFTP doesn't supports HTTP 1.1 proxies -- but no NTLM (forgot to mention that I need that). I'm looking into alternatives. – stb Jan 27 '20 at 10:53
  • Did you mean that *"FluentFTP **does** support HTTP 1.1. proxies, but not NTML"*? – Martin Prikryl Jan 27 '20 at 10:56
  • That's the way it looks: https://github.com/robinrodricks/FluentFTP/blob/master/FluentFTP/Proxy/FtpClientHttp11Proxy.cs#L72 – stb Jan 27 '20 at 16:13