FTP/SSL via PowerShell

0 votes
asked Aug 16, 2011 by Scott (130 points)
edited Aug 16, 2011

Can you please provide some assistance using this product via PowerShell. I have a script that is running using the sFTP libraries, but now have a need to use FTP/SSL.

The main issue I am having is storing and accessing the .pfx keys provided by the company we are connecting to. Has anyone done this?

Any and all help would be great.

Applies to: Rebex FTP/SSL

1 Answer

+1 vote
answered Aug 16, 2011 by Lukas Pokorny (120,490 points)
edited Aug 16, 2011

We have a blogpost describing the basics: Using FTP or SFTP in PowerShell

Getting the .pfx keys to work requires few additional lines of code. If these are client certificates that are intended for client authentication, the following code should do the trick:

[Reflection.Assembly]::LoadFrom("C:\Program Files\Rebex\FTP for .NET 2.0\bin\release\Rebex.Net.Ftp.dll")
[Reflection.Assembly]::LoadFrom("C:\Program Files\Rebex\FTP for .NET 2.0\bin\release\Rebex.Net.SecureSocket.dll")

$certificate = [Rebex.Security.Certificates.CertificateChain]::LoadPfx("c:\...\ClientCerts.pfx", "password")

$params = New-Object Rebex.Net.TlsParameters
$params.CertificateRequestHandler = [Rebex.Net.CertificateRequestHandler]::CreateRequestHandler($certificate)

$ftp = New-Object Rebex.Net.Ftp
$ftp.Connect("ftp.example.com", 21, $params, [Rebex.Net.FtpSecurity]::Explicit)

Please refer to our FTP/SSL tutorial for more information about these classes and methods.

...