Topic "WebDav over Powershell with 2 Factor auth"

Author Message



Perhaps someone could point me in the right direction. I'm trying to connect to a WebDav host using WinSCP & Powershell
Connecting to this WebDav host works 100% in the WinSCP client itself. i specify the location of the certificate, put the host address and remote directories in under advanced. when i then connect I am prompted for 2 passwords. First the certificate PW, then the user / pass for the webdav host itself.

I would now like to do this via powershell. I noticed that you can generate the session code from the client - see below
the generated code specified the webdav host username and the certificate password. The actual webdav host password is not specified.

# Load WinSCP .NET assembly
Add-Type -Path "WinSCPnet.dll"

# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Webdav
HostName = ""
PortNumber = 443
UserName = "hostusername"
Password = "certificatepassword"
WebdavSecure = $True
TlsClientCertificatePath = "C:\OpenSSL-Win64\certificate"

$session = New-Object WinSCP.Session

# Connect

# Your code

In the end when I try to connect i get the following error

Exception calling "Open" with "1" argument(s): "SSL handshake failed, client certificate was requested: SSL error: sslv3 alert handshake failure
Connection failed."
At line:20 char:5
+ $session.Open($sessionOptions)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Smile [], MethodInvocationException
+ FullyQualifiedErrorId : SessionRemoteException

If it works with the client surely it can be done using the .net assembly and PS

thanks in advance for any help or suggestions


PrivateKeyPassphrase - this option allowed me to specify the cert password
connection works now

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