Issue with .NET Automation Connection
I am currently experiencing an issue where WinSCP is able to connect to our FTP server within the GUI, but we cannot get the same results using .NET automation. When I connect and export the session code it seems to match what I have scripted, I can't use the generated code exactly as I get a syntax error I believe stemming from the fact that I am using PowerShell 5.1 and not a later version. If I connect successfully using the GUI and then export the session I get the attached output when exporting to PowerShell (password has been removed), However, when I try to run the below script, which I think is functionally equivalent, this includes the port which my export didn't but leaving it off seems to get the same, I get this error connecting:
The user and password end up set the same, I'm wondering if it is related to the certificate in some way as at times I do get prompts using the GUI that I it does not trust the full chain of the TLS certificate for FTPS.
Connection failed.
Requested action aborted: internal error in processing.
try { # Load WinSCP .NET assembly Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll" # Setup session options $sessionOptions = New-Object WinSCP.SessionOptions $sessionOptions.Protocol = [WinSCP.Protocol]::ftp $sessionOptions.FtpSecure = [WinSCP.FtpSecure]::Implicit $sessionOptions.HostName = 'ftp-app' $sessionOptions.UserName = $user $sessionOptions.PortNumber = 990 $sessionOptions.Password = $password $sessionOptions.TlsHostCertificateFingerprint = "4a:db:1d:40:2f:ba:60:a8:ef:c7:7f:c0:5e:be:40:b9:07:21:13:fa:49:82:00:e9:b7:d9:a2:78:3e:37:f8:09" $session = New-Object WinSCP.Session try { # Open Connection $session.Open($sessionOptions) # Download files $transferOptions = New-Object WinSCP.TransferOptions $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary $transferResult = $session.GetFiles($remoteDir + "/" + $match , $localDir + "\" , $move, $transferOptions) # Throw on any error $transferResult.Check() # Print results foreach ($transfer in $transferResult.Transfers) { writeLog "Download of $($transfer.FileName) succeeded" $log } } finally { # Disconnect, go home $session.Dispose() } writeLog "Processing Complete." $log exit 0 } catch [Exception] { writeLog $_.Exception.Message $log exit 1 }