Я завершаю шаги 1-4 из this answer, который добавляет мой сертификат в «доверенные корневые центры сертификации»> «Сертификаты», а сертификат предоставляется <All>
.PowerShell - доверенный сертификат Windows, не аутентифицирующий SSL по FTP
Выполнение приведенного ниже кода PowerShell с ошибкой The remote certificate is invalid according to the validation procedure
при $ftp_request.EnableSsl = $true
. Это удается, когда $ftp_request.EnableSsl = $false
.
$file_folder = "C:\Users\username\Desktop"
$file_name = "test.txt"
$file_path = "$file_folder\$file_name"
$ftp_path = "ftp://127.0.0.1/$file_name"
$username = "user"
$pwd = "pass"
# Create a FTPWebRequest object to handle the connection to the ftp server
$ftp_request = [System.Net.FtpWebRequest]::Create($ftp_path)
# set the request's network credentials for an authenticated connection
$ftp_request.Credentials =
New-Object System.Net.NetworkCredential($username, $pwd)
$ftp_request.UseBinary = $true
$ftp_request.UsePassive = $true
$ftp_request.KeepAlive = $false
$ftp_request.EnableSsl = $true
$ftp_request.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
$file_contents = Get-Content -en byte $file_path
$ftp_request.ContentLength = $file_contents.Length
$ftp_stream = $ftp_request.GetRequestStream()
$ftp_stream.Write($file_contents, 0, $file_contents.Length)
$ftp_stream.Close()
$ftp_stream.Dispose()
Я знаю, что это можно вручную справиться с этим, написав обработчик ServicePointManager.ServerCertificateValidationCallback
, но я хотел бы иметь SSL сертификаты обрабатываются автоматически менеджером Cert Windows.