gpt4 book ai didi

PowerShell - Windows 可信证书未通过 FTP 验证 SSL

转载 作者:太空宇宙 更新时间:2023-11-03 13:37:38 25 4
gpt4 key购买 nike

我完成了 this answer 的第 1-4 步,它将我的证书添加到“受信任的根证书颁发机构”>“证书”,并且证书被授予 <All>预期目的。

执行以下 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 证书由 Windows 证书管理器自动处理。

最佳答案

$ftp_path = "ftp://127.0.0.1/$file_name"

为所有目的将证书添加为受信任并不意味着所有主机都信任该证书。您用于连接的主机名仍然必须与证书的主题相匹配。虽然您没有提供有关证书本身的任何信息,但我的猜测是您的证书不是针对主题“127.0.0.1”颁发的。

关于PowerShell - Windows 可信证书未通过 FTP 验证 SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34500173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com