【发布时间】:2015-03-17 20:43:17
【问题描述】:
我正在尝试将文件上传到 FTP 服务器,我需要使用客户端证书而不是用户名和密码进行身份验证。
var fullFtpPath = String.Concat(ftpItem.FtpAddress, "/", record, ".txt");
FtpWebRequest request = (FtpWebRequest) WebRequest.Create(fullFtpPath);
request.Credentials = new NetworkCredential(ftpItem.Username, ftpItem.Password);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.UseBinary = true;
request.UsePassive = ftpItem.UsePassive;
request.EnableSsl = ftpItem.UseSSL;
request.ContentLength = bytes.Length;
using(Stream s = request.GetRequestStream()) {
s.Write(bytes, 0, bytes.Length);
}
FtpWebResponse response = (FtpWebResponse) request.GetResponse();
Debug.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
db.LogExport(siteId, fullFtpPath, record, true, response.StatusDescription);
response.Close();
以上是我当前的代码,但我不确定如何实现证书身份验证,或者是否可以这样做。我必须创建证书吗?或者服务器会给我一个证书,我就在我的请求中设置它?
【问题讨论】:
标签: c# ssl ftp client-certificates ftps