C# 使用C中的代理连接到FTPS#

C# 使用C中的代理连接到FTPS#,c#,.net,ftp,ftpwebrequest,ftps,C#,.net,Ftp,Ftpwebrequest,Ftps,我下面的代码在没有代理的情况下在我的计算机上运行得非常好。但在客户机服务器中,他们需要向FTP客户机(FileZilla)添加代理才能访问FTP。但当我添加代理时,它会说 使用代理时无法启用SSL FTP代理 var proxyAddress = ConfigurationManager.AppSettings["ProxyAddress"]; WebProxy ftpProxy = null; if (!string.IsNullOrEmpty(proxyAddress)) { var

我下面的代码在没有代理的情况下在我的计算机上运行得非常好。但在客户机服务器中,他们需要向FTP客户机(FileZilla)添加代理才能访问FTP。但当我添加代理时,它会说

使用代理时无法启用SSL

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 framework确实不支持通过代理的TLS/SSL连接

您必须使用第三方FTP库

还要注意,您的代码没有使用“隐式”FTP。它使用“显式”FTP。要么


例如,对于,您可以使用:

// 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);
}
有关的选项,请参见


(我是WinSCP的作者)

这与常规ftp客户端连接吗?@Saruman是的