2017-12-28 20 views
4

私の下のコードはプロキシなしでコンピュータで完全に正常に動作します。しかし、クライアントサーバーでは、FTPにアクセスできるように、FTPクライアント(FileZilla)にプロキシを追加する必要があります。しかし、プロキシを追加すると、C#でプロキシを使用してFTPSに接続

プロキシを使用すると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(); 
+0

これは、通常のftpクライアントで接続されていますか? –

+0

@サルマンはいそうです – Reynan

答えて

2

.NETフレームワークは確かに、プロキシ経由TLS/SSL接続をサポートしていません。

サードパーティのFTPライブラリを使用する必要があります。

また、あなたのコードは「暗黙の」FTPSを使用していないことにも注意してください。 「明示的」なFTPSを使用しています。 Implicit FTPS is not supported by .NET frameworkのいずれかです。例えば


WinSCP .NET assemblyでは、使用することができます:SessionOptions.AddRawSettingsためのオプションについて

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

を、raw settingsを参照してください。

(私はWinSCPのの著者です)

関連する問題