PowerShell script to download a specific version of WinSCP

Today I was helping a BizTalk Server customer migrate their process from using the FTP adapter to the SFTP adapter. And if you are familiar with the BizTalk SFTP adapter, you will be aware of the painful process of choosing the correct version of WinSCP and how that hell we need to do to work correctly with the BizTalk Server, which is quite simple in general:

  • Download WinSCP and the .net Library, ensuring you get the correct version!
  • Copy the .exe and .dll to the BizTalk installation folder
  • DO NOT gac anything. If you GAC the .net library, it will not work because it expects WinSCP.exe to be in the same path, so that’s why they both go into the BizTalk installation folder.

However, the biggest issue is: what is the correct WinSCP version I need for my version of BizTalk Server 2016 or 2020?

And for that reason, Thomas E. Canter, on his day as a Phidiax consultant, decided to create this fantastic PowerShell script BizTalk WinSCP Installer, which during the years, has evolved and was improved by several people like Michael Stephenson, Nicolas Blatter, Niclas Öberg and myself.

If your environment has access to the internet, then I will recommend you use that script to install WinSCP! However, my client didn’t have access to the internet from the production server, and to complicate it a little bit, it didn’t have the same Build version. Let’s say in the test environment, it did have BizTalk Server 2016 with Feature Pack 3 and Cumulative Update 9, but in production, we would find BizTalk Server 2016 with Feature Pack 3 and Cumulative Update 5. That means we couldn’t copy the files from other environments to production. We had to use a different WinSCP version.

To address this scenario, I created a simple PowerShell version that you could choose the version you want to download and that you can run on any machine with access to the internet without checking the Build version you have in your environment.

This is a simple abstract of the PowerShell script:

$checkExeExists = Test-Path $targetNugetExe
if(-not $checkExeExists)
{
    if ($PSCmdlet.ShouldProcess("$sourceNugetExe -OutFile $targetNugetExe", "Run Invoke-WebRequest ")) {
        Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe
        $targetNugetExeExists = Test-Path $targetNugetExe
        if (-not $targetNugetExeExists) {
            $Continue = $false
            Write-Error "`n$bangString";
            Write-Error "The download of the Nuget EXE from";
            Write-Error $sourceNugetExe;
            Write-Error "did not succeed";
            Write-Error "$bangString";
        }
        else{
            Write-Success "nuget.exe download successfully."
        }
    }
}

if ($PSCmdlet.ShouldProcess("$getWinSCP", "Run Command")) {
    Invoke-Expression "& $getWinSCP";
    $WinSCPEXEExists = Test-Path $WinSCPEXEDownload
    $WinSCPDLLExists = Test-Path $WinSCPDllDownload
    if (-not $WinSCPDLLExists) {
        $Continue = $false
        Write-Error "`n$bangString";
        Write-Error "WinSCP $winSCPVersion was not properly downloaded.";
        Write-Error "Check the folder and error messages above:";
        Write-Error "$nugetDownloadFolder";
        Write-Error "And determine what files did download or did not download.";
        Write-Error "$bangString";
    }
    else{
        Write-Success "WinSCP $winSCPVersion was properly downloaded."
    }
}

THESE POWERSHELL SCRIPTS ARE PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND.

Where can I download it?

You can download the complete Azure Function source code here:

Hope you find this helpful! So, if you liked the content or found it helpful and want to help me write more content, you can buy (or help buy) my son a Star Wars Lego! 

Author: Sandro Pereira

Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc. He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.

Leave a Reply

Your email address will not be published. Required fields are marked *

turbo360

Back to Top