Scripting download and installation of .Net assembly

Advertisement

Aeschere
Joined:
Posts:
2

Scripting download and installation of .Net assembly

Hello,

I am trying to write a script that I can use to automatically install and configure a brand new Windows server. One of the key components for this is WinSCP so that I can download the required files from our FTP server.
When I am using the WinSCP module I am able to download the files but this requires me to manually provide credentials for the connection so I am looking for a way to use the .Net assembly.
However, I cannot seem to download the ZIP file from the WinSCP website through a script.

I am currently using this
$source = "https://winscp.net/download/WinSCP-5.9.6-Automation.zip/download"
$filename = "$destination\winscp.zip"
 
(New-Object System.Net.WebClient).DownloadFile($source, $filename)
But all I get is a winscp.zip file of 10KB that cannot be opened. When trying to use the CDN or Alternative download link it is possible to download the file but those URL's come with a personalized and times code which causes the download to fail the next time I run the script.

Is there a way to download the file directly?

Thanks in advance.

Reply with quote

Advertisement

Aeschere
Joined:
Posts:
2

Seems like I found another way by using the WinSCP module.
Save-Module -Name WinSCP -Path $destination\
Install-Module -Name WinSCP -Force
Import-Module -Name WinSCP
 
Add-Type -Path "$destination\WinSCP\5.9.6.0\lib\WinSCPnet.dll"
 
$session = New-Object WinSCP.Session
$session.ExecutablePath = "$destination\WinSCP\5.9.6.0\bin\WinSCP.exe"
This way you can still set SessionOptions (including all credentials) and doesn't require a download from the WinSCP website. The only downside is that there is a hardcoded version number in there which should be changed when there is a new version.

Reply with quote

Advertisement

You can post new topics in this forum