2017-12-28 17 views
4

Mein unten Code funktioniert einwandfrei in meinem Computer ohne Proxy. Aber auf dem Client-Server müssen sie dem FTP-Client (FileZilla) einen Proxy hinzufügen, um auf das FTP zugreifen zu können. Aber wenn ich Proxy hinzufüge, heißt esVerbinden mit FTPS mit Proxy in C#

SSL kann nicht aktiviert werden, wenn Sie einen Proxy verwenden.

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-Verbindung

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(); 
+0

Enthält diese mit einem normalen FTP-Client eine Verbindung herstellen? –

+0

@ Saruman ja es tut – Reynan

Antwort

2

.NET-Framework in der Tat nicht TLS/SSL-Verbindungen über Proxy unterstützt.

Sie müssen eine FTP-Bibliothek eines Drittanbieters verwenden.

Beachten Sie auch, dass Ihr Code nicht "implizite" FTPS verwendet. Es verwendet "explizite" FTPS. Implicit FTPS is not supported by .NET framework entweder.


Zum Beispiel mit WinSCP .NET assembly können Sie verwenden:

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

Für die Optionen für SessionOptions.AddRawSettings finden raw settings.

(ich bin der Autor von WinSCP)