Hello there,
Found this script online that demonstrates how to connect to an FTP server, examine the server's SSL/TLS certificate, and then, if it meets the application's security requirements, proceed to authenticate.
Add-Type -Path "xyz".
$ftp = New-Object xyz.Ftp2
$ftp.Hostname = "www.authtls-ftps-server.com"
$ftp.Username = "FTP_LOGIN"
$ftp.Password = "FTP_PASSWORD"
$ftp.AuthTls = $true
$ftp.Port = 21
Connect to the FTP server using explicit TLS (AUTH TLS).
$success = $ftp.ConnectOnly()
if ($success -ne $true) {
$($ftp.LastErrorText)
exit
}
Get the FTP server's certificate.
$serverCert = $ftp.GetSslServerCert()
if ($ftp.LastMethodSuccess -ne $true) {
$($ftp.LastErrorText)
exit
}
Assuming the certificate is OK, proceed to authenticate with the FTP server.
$success = $ftp.LoginAfterConnectOnly()
if ($success -ne $true) {
$($ftp.LastErrorText)
exit
}
Proceed with uploading/download files, etc...
$ftp.Disconnect()
$("Success.")
---------------------------------------------------------------------------------------------------------------------------
--If the reply is helpful, please Upvote and Accept it as an answer–