【问题标题】:How to fetch file by FTP via squid proxy using .NET Core (FtpWebRequest)?如何使用 .NET Core (FtpWebRequest) 通过 squid 代理通过 FTP 获取文件?
【发布时间】:2020-05-12 16:36:50
【问题描述】:

根据https://docs.microsoft.com/en-us/dotnet/api/system.net.ftpwebrequest.proxy?view=netcore-3.1 FtpWebRequest 不支持.NET Core 代理。有其他选择吗?

我需要通过带有代理身份验证 (NTLM) 的 squid 代理(即 FTP over HTTP)访问 FTP 文件。

这是示例代码:

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);

如果您将此代码中的 squid host/user/pass 替换为您的,您将看到此 csproj 文件可以正常工作:

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

但它不再适用于 .NET Core:

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

【问题讨论】:

    标签: c# .net-core proxy ftp squid


    【解决方案1】:

    除了FtpWebRequest,.NET 框架中没有其他 FTP 实现。而FtpWebRequest 本身已被弃用,不会得到改进。您必须使用第 3 方 FTP 客户端库。

    见:


    一般情况下,您可以使用FluentFTPmy WinSCP .NET assembly

    虽然两者都不支持 NTLM 身份验证(您稍后添加的要求)。我不知道有任何其他免费的广泛使用的 .NET FTP 库。

    【讨论】:

    • 感谢您提供快速而有帮助的答案(顺便感谢 WinSCP)。 FluentFTP 不支持 HTTP 1.1 代理——但不支持 NTLM(忘了说我需要那个)。我正在寻找替代方案。
    • 您的意思是 "FluentFTP 是否支持 HTTP 1.1. 代理,但不支持 NTML"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多