2013-12-11 121 views
3

尝试通过C#桌面应用程序将文件上载到我的服务器时出现以下错误:“远程证书根据验证过程无效。 “这与SSL证书有关。这是我的网站,由Arvixe托管。下面是我使用的代码:SSL证书问题 - 根据验证程序,远程证书无效

 public void Upload(string strFileToUpload) 
    { 
     FileInfo fiToUpload = new FileInfo(strFileToUpload); 
     FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.sd.arvixe.com/" + strDomain + "/wwwroot/OnlineGalleries/" + strOnlineGalleryName + "/Gallery/" + fiToUpload.Name); 
     request.EnableSsl = true; 
     request.Method = WebRequestMethods.Ftp.UploadFile; 
     request.Credentials = new NetworkCredential("usr", "psw"); 
     Stream sFTP = request.GetRequestStream(); 
     FileStream file = File.OpenRead(strFileToUpload); 
     int length = 1024; 
     byte[] buffer = new byte[length]; 
     int bytesRead = 0; 
     do 
     { 
      bytesRead = file.Read(buffer, 0, length); 
      sFTP.Write(buffer, 0, bytesRead); 
     } 
     while (bytesRead != 0); 
     file.Close(); 
     sFTP.Close(); 
    } 

此代码工作正常,如果我设置request.EnableSsl =假。我不知道该怎么做。我已经尝试将URI设置为ftps://和sftp://,但是它们返回错误“无法识别URI前缀”。任何帮助表示赞赏。

+0

http://ftps.codeplex.com/检查您是否已经打到这里记录的FtpWebRequest的限制。 'sftp'不是'ftps'。确保你去维基百科,了解其中的差异。 –

回答

8

难以测试您的代码,因为它连接到公共服务。但是,如果你只是想忽略SSL错误或许这可以帮助你做到这一点:

System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true; 
+1

谢谢你,现在已经找了几个星期了。 – b729sefc

+0

非常感谢你 – om471987

相关问题