Host key wasn't verified
Hi,
i got a script to put files on a remote server but it returns the same error over and over again : " Host Key wasn't verified"
I can make my connection through the Winscp GUI but when running the script it fails every time
try
{
# Load WinSCP .NET assembly
# Use "winscp.dll" for the releases before the latest beta version.
#[Reflection.Assembly]::LoadFrom("WinSCPnet.dll") | Out-Null
[Reflection.Assembly]::LoadFrom("C:\Batch\WinSCP4\WinSCP.dll") | Out-Null
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = "193.191.216.90"
$sessionOptions.UserName = "ext_myUser"
$sessionOptions.Password = ""
$sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
$sessionOptions.SshPrivateKeyPath = "C:\XX\XX\WinSCP4\privatekey.ppk"
$session = New-Object WinSCP.Session
try
{
# Connect
$session.Open($sessionOptions)
$remotePath = "In\All"
$localPath = "c:\FTPDATA\Production\IS\80111202\OUT\Fedopress\"
$files = ""
# Upload files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$transferResult = $session.PutFiles($localPath + "\*", $remotePath, $False, $transferOptions)
# Throw on any error
$transferResult.Check()
# Print results
foreach ($transfer in $transferResult.Transfers)
{
Write-Host ("Upload of {0} succeeded" -f $transfer.FileName)
$Files = $files + $transfer.FileName + "`r`n"
}
}
finally
{
# Disconnect, clean up
$session.Dispose()
}
}
catch [Exception]
{
Write-Host $_.Exception.Message
exit 1
}
can you please advice
thanks in advance
i got a script to put files on a remote server but it returns the same error over and over again : " Host Key wasn't verified"
I can make my connection through the Winscp GUI but when running the script it fails every time
try
{
# Load WinSCP .NET assembly
# Use "winscp.dll" for the releases before the latest beta version.
#[Reflection.Assembly]::LoadFrom("WinSCPnet.dll") | Out-Null
[Reflection.Assembly]::LoadFrom("C:\Batch\WinSCP4\WinSCP.dll") | Out-Null
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = "193.191.216.90"
$sessionOptions.UserName = "ext_myUser"
$sessionOptions.Password = ""
$sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
$sessionOptions.SshPrivateKeyPath = "C:\XX\XX\WinSCP4\privatekey.ppk"
$session = New-Object WinSCP.Session
try
{
# Connect
$session.Open($sessionOptions)
$remotePath = "In\All"
$localPath = "c:\FTPDATA\Production\IS\80111202\OUT\Fedopress\"
$files = ""
# Upload files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$transferResult = $session.PutFiles($localPath + "\*", $remotePath, $False, $transferOptions)
# Throw on any error
$transferResult.Check()
# Print results
foreach ($transfer in $transferResult.Transfers)
{
Write-Host ("Upload of {0} succeeded" -f $transfer.FileName)
$Files = $files + $transfer.FileName + "`r`n"
}
}
finally
{
# Disconnect, clean up
$session.Dispose()
}
}
catch [Exception]
{
Write-Host $_.Exception.Message
exit 1
}
can you please advice
thanks in advance