FileZilla를 서버 및 DNS 서비스로 사용하고 있으므로 로컬 컴퓨터 IP를 사용할 필요가 없습니다. (그러나 다음 두 가지 방법 모두 시도했습니다.)FTPS (SSL)의 인증서 유효성 검사/설치?
System.Net.FtpWebRequest가 작동하도록 시도한 후에 나는 (SO에 대한 몇 가지 게시물을 포함하여) 주위를 읽었으며 SSL 지원이 해당 라이브러리에 적합하지 않음을 발견했습니다. 그것은 일반 FTP 작업을했지만, 나는 SSL을 강요하려고 할 때, 내가 말하는 인증서 유효성 검사 오류가 발생했습니다 : The remote certificate is invalid according to the validation procedure.
그래서, 나는 몇 가지 주변 검색을 수행하고 알렉스 FTPS 클라이언트 라이브러리를 발견했습니다. 다음은 내가 작성한 코드입니다.
class FTPSWorker
{
public static void UploadFile(string sourceFile, string targetFile, string ftpIP, string ftpUser, string ftpPass)
{
try
{
using (FTPSClient client = new FTPSClient())
{
client.Connect(ftpIP, new NetworkCredential(ftpUser, ftpPass),
ESSLSupportMode.CredentialsRequired | ESSLSupportMode.DataChannelRequested);
client.SetTransferMode(ETransferMode.Binary);
client.PutFile(sourceFile, targetFile);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
불행히도 정확한 인증서 오류가 발생했습니다. 그러나 FileZilla 클라이언트를 사용하여 FTP 서버에 완벽하게 액세스 할 수 있습니다. 그래서, 나는 증명서 문제가 있어야 할 것이라고 생각했습니다.
내 서버는 다음 로그 항목 보여주는 것을주의해야한다 : 이것은 절대적으로 동일한 오류가
The remote certificate is invalid according to the validation procedure.
: 클라이언트 (C# WPF 응용 프로그램)이 오류가 발생 동안
Welcome Message
AUTH TLS
234 Using authentication type TLS
SSL connection established
disconnected
을 .NET 라이브러리와 MSDN 코드를 사용하면됩니다.
는 좀 더 연구를 다음과 비슷한 솔루션을 발견했습니다
"The remote certificate is invalid according to the validation procedure." using Gmail SMTP server
The remote certificate is invalid according to the validation procedure 그러나 그들은 단지 위험 해킹처럼 보인다 ... 그리고 그들은이 일을하면서, 거기입니다 인증 정보를 표시하고 사용자가 유효성을 검사하도록 설정하는 방법/현재 사용중인 기본 예/아니오 외에 설치 하시겠습니까?
지금 (I 알렉스의 라이브러리를 도랑 및 기본 .NET으로 되돌아 갔다) 내 코드 :
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(FTPWorker.ValidateServerCertificate);
public class FTPWorker
{
public static void UploadFile(string sourceFile, string targetFile, string ftpIP, string ftpUser, string ftpPass)
{
try
{
string filename = "ftp://" + ftpIP + "/test/" + targetFile;
FtpWebRequest ftpReq = (FtpWebRequest)WebRequest.Create(filename);
ftpReq.Method = WebRequestMethods.Ftp.UploadFile;
ftpReq.Credentials = new NetworkCredential(ftpUser, ftpPass);
ftpReq.UsePassive = true;
ftpReq.EnableSsl = true;
ftpReq.UseBinary = true;
ftpReq.KeepAlive = false;
byte[] b = File.ReadAllBytes(sourceFile);
ftpReq.ContentLength = b.Length;
using (Stream s = ftpReq.GetRequestStream())
{
s.Write(b, 0, b.Length);
}
FtpWebResponse ftpResp = (FtpWebResponse)ftpReq.GetResponse();
if (ftpResp != null)
{
MessageBox.Show(ftpResp.StatusDescription);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
public static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
if (sslPolicyErrors == SslPolicyErrors.None)
return true;
else
{
if (System.Windows.Forms.MessageBox.Show("The server certificate is not valid.\nAccept?",
"Certificate Validation", System.Windows.Forms.MessageBoxButtons.YesNo,
System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
return true;
else
return false;
}
}
}
귀하의 코드는 검사를 위해 사용자에게 인증서를 절대적으로 제공 할 수 있으며 유효성 검사 콜백에서 코드에 반환되는 인증서 유효성 확인과 관련된 특정 문제를 표시해야합니다. – EricLaw