我下面的代码在我的电脑上运行得很好,没有代理.但是在客户端服务器中,他们需要向 FTP 客户端 (FileZilla) 添加代理才能访问 FTP.但是当我添加代理时它说
My below code works perfectly fine in my computer without proxy. But in client server they need to add proxy to the FTP client (FileZilla) to be able to access the FTP. But When I add proxy it says
使用代理时无法启用 SSL.
SSL cannot be enabled when using a proxy.
FTP 代理
var proxyAddress = ConfigurationManager.AppSettings["ProxyAddress"];
WebProxy ftpProxy = null;
if (!string.IsNullOrEmpty(proxyAddress))
{
var proxyUserId = ConfigurationManager.AppSettings["ProxyUserId"];
var proxyPassword = ConfigurationManager.AppSettings["ProxyPassword"];
ftpProxy = new WebProxy
{
Address = new Uri(proxyAddress, UriKind.RelativeOrAbsolute),
Credentials = new NetworkCredential(proxyUserId, proxyPassword)
};
}
FTP 连接
var ftpRequest = (FtpWebRequest)WebRequest.Create(ftpAddress);
ftpRequest.Credentials = new NetworkCredential(
username.Normalize(),
password.Normalize()
);
ServicePointManager.ServerCertificateValidationCallback +=
(sender, cert, chain, sslPolicyErrors) => true;
ServicePointManager.Expect100Continue = false;
ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
ftpRequest.EnableSsl = true;
//ftpRequest.Proxy = ftpProxy;
var response = (FtpWebResponse)ftpRequest.GetResponse();
.NET 框架确实不支持通过代理的 TLS/SSL 连接.
.NET framework indeed does not support TLS/SSL connections over proxy.
您必须使用第 3 方 FTP 库.
You have to use a 3rd party FTP library.
另外请注意,您的代码没有使用隐式"FTPS.它使用显式"FTPS..NET 框架也不支持隐式 FTPS.
例如,对于 WinSCP .NET 程序集,您可以使用:
For example with WinSCP .NET assembly, you can use:
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Ftp,
HostName = "example.com",
UserName = "user",
Password = "mypassword",
FtpSecure = FtpSecure.Explicit, // Or .Implicit
};
// Configure proxy
sessionOptions.AddRawSettings("ProxyMethod", "3");
sessionOptions.AddRawSettings("ProxyHost", "proxy");
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
var listing = session.ListDirectory(path);
}
有关 SessionOptions.AddRawSettings 的选项,请参阅 原始设置.
(我是 WinSCP 的作者)
这篇关于在 C# 中使用代理连接到 FTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
ASP.NET Core 使用 Azure Active Directory 进行身份验证并ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 进行身
ASP.NET Core 2.0 Web API Azure Ad v2 令牌授权不起作用ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授权不起作用)
ASP Core Azure Active Directory 登录使用角色ASP Core Azure Active Directory Login use roles(ASP Core Azure Active Directory 登录使用角色)
如何获取守护进程或服务器到 C# ASP.NET Web API 的How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何获取守护进程或服务器到 C# ASP.N
.Net Core 2.0 - 获取 AAD 访问令牌以与 Microsoft Graph.Net Core 2.0 - Get AAD access token to use with Microsoft Graph(.Net Core 2.0 - 获取 AAD 访问令牌以与 Microsoft Graph 一起使用)
异步调用时 Azure KeyVault Active Directory AcquireTokenAAzure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(异步调用时 Azure KeyVault Active Directory AcquireTokenAsync 超