Topic "Scripting download and installation of .Net assembly"

Author Message
[View user's profile]

Joined: 2017-07-26
Posts: 2

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 = ""
$filename = "$destination\"

(New-Object System.Net.WebClient).DownloadFile($source, $filename)

But all I get is a 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.
[View user's profile]

Joined: 2017-07-26
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\\lib\WinSCPnet.dll"

$session = New-Object WinSCP.Session
$session.ExecutablePath = "$destination\WinSCP\\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.

[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26911
Location: Prague, Czechia
Download the file from SourceForce, as shown here:

Your other post does not make any sense to me.

You can post new topics in this forum


What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License