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 cannot be enabled when using a proxy.
FTP proxy
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 connection
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 indeed does not support TLS/SSL connections over proxy.
You have to use a 3rd party FTP library.
Also note that your code is not using "implicit" FTPS. It's using "explicit" FTPS. Implicit FTPS is not supported by .NET framework either.
For example with WinSCP .NET assembly, you can use:
For the options for
SessionOptions.AddRawSettings
, see raw settings.(I'm the author of WinSCP)