Download files from WebDav with certificate via CLI

Advertisement

Pascal
Joined:
Posts:
1

Download files from WebDav with certificate via CLI

Hello,

I have a WebDav folder from which I have to download data once a month. I would like to automate that using Powershell and WinSCP.
I already have a saved session for that, which is working properly, but I can find no way to safe the Certificate Passphrase.

The Script Generator gives me this:

# WinSCP .NET assembly laden
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"

$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Webdav
HostName = "webdav.remotehost.test"
PortNumber = 443
UserName = "User_Name"
Password = "somepwd$123"
WebdavSecure = $True
TlsClientCertificatePath = "C:\Cert\60654_20171012.p12"

}

$sessionOptions.AddRawSettings("ProxyMethod", "3")
$sessionOptions.AddRawSettings("ProxyHost", "webproxy.company.de")
$sessionOptions.AddRawSettings("ProxyPort", "8080")

$session = New-Object WinSCP.Session

try
{
# Connect
$session.Open($sessionOptions)

# Your code
}
finally
{
$session.Dispose()
}


Hint: I altered personal information but there is a "$" in the Password which cannot be changed and there is a startfolder. The complete URL looks like this https://webdav.remotehost.test/~0000010656/

Running this gives me the following error: SSL handshake failed, client certificate was requested: SSL error: sslv3 alert handshake failure

Does anyone know if there is anyway to get this running?

Thanks

Pascal

Reply with quote

Advertisement

Guest

Re: Download files from WebDav with certificate via CLI

martin wrote:


Thank you, but there are still some problems.

1. How can I use the Dollar sign in a password? I tried like this "somepwd`$123"
2. How do I specify the Remote directory?
3. I still get the following error: "Server certificate verification failed: issuer is not trusted" is there another option to ignore that?

Thanks.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,517
Location:
Prague, Czechia

Re: Download files from WebDav with certificate via CLI

1. How can I use the Dollar sign in a password? I tried like this "somepwd`$123"
Looks ok to me. Do you have any problem with that?

2. How do I specify the Remote directory?
For what?

3. I still get the following error: "Server certificate verification failed: issuer is not trusted" is there another option to ignore that?
To verify certificates issues by untrusted authority, use SessionOptions.TlsHostCertificateFingerprint:
https://winscp.net/eng/docs/library_sessionoptions#tlshostcertificatefingerprint

Reply with quote

Advertisement

You can post new topics in this forum