ssl-Authentication我可以定义超时吗?

时间:2014-10-24 08:04:09

标签: powershell ssl connection-timeout


我有一小段PS代码来创建一个ssl-stream来访问我的电子邮件帐户 这工作正常,直到今天ssl-server没有响应身份验证,脚本挂起在$ sslStream.AuthenticateAsClient($ server);等待服务器的ssl-stream:

try {
  $tcpClient = New-Object -TypeName System.Net.Sockets.TcpClient
  Write-Host $(Get-Date -format "dd-MMM-yyyy HH:mm:ss") " starting the Connect..        `r" -NoNewLine
  $tcpClient.Connect($server, 995)
  Write-Host $(Get-Date -format "dd-MMM-yyyy HH:mm:ss") " ok connected, starting Auth.. `r" -NoNewLine
  if($tcpClient.Connected) {
      [System.Net.Security.SslStream] $sslStream = $tcpClient.GetStream()
      $sslStream.AuthenticateAsClient($server);
      Write-Host $(Get-Date -format "dd-MMM-yyyy HH:mm:ss") " ok auth.!, starting login ..`r" -NoNewLine

有没有办法只等n秒钟来回答服务器并以错误代码退出脚本呢?

0 个答案:

没有答案