Error with PowerShell and XML settings file for WinSCP Protocol setting

Advertisement

adamardaa
Guest

Error with PowerShell and XML settings file for WinSCP Protocol setting

Hi everyone
I get this error:
The value supplied is not valid, or the property is read-only. Change the value, and then try again.
If I hard code the value it works fine. I've checked the value is being pulled from the xml file by doing a write-output and it's fine. The other values work fine, it's just the Protocol. I've tried all four combinations of "" around the value. Any ideas? Huge thanks. Adam
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    #Protocol = "[WinSCP.Protocol]::Ftp"
    Protocol = $configfile.settings.FTPServerSettings.protocol
    HostName = $configfile.settings.FTPServerSettings.hostname
    PortNumber = $configfile.settings.FTPServerSettings.portnumber
    UserName = $configfile.settings.FTPServerSettings.username
    Password = $configfile.settings.FTPServerSettings.password
}
 
$session = New-Object WinSCP.Session
settings.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- setting file for use with WinSCP -->
<settings>
   <FileSettings>
      <LogFile>E:\WinSCP\Bentley</LogFile>
   </FileSettings>
   <FTPServerSettings>
      <protocol>[WinSCP.Protocol]::ftp</protocol>
      <hostname>ftp.blahblah.co.uk</hostname>
      <portnumber>21</portnumber>
      <username>blahblahblah</username>
      <password>blah</password>
      <ftpsecure></ftpsecure>
      <tlshostcertificatefingerprint></tlshostcertificatefingerprint>
   </FTPServerSettings>
<!--   <FileDownload>
      <remotePath>/OUT/*</remotepath>
      <localPath>C:\Temp\</localpath>
   </FileDownload>
   <FileUpload>
      <localpath>C:\Temp\*"</localpath>
      <remotepath>/IN/</remotepath>
   </FileUpload> -->
</settings>

Reply with quote

Advertisement

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

Re: Error with powershell and xml settings file for WINSCP Protocol setting

PowerShell won't convert string "[WinSCP.Protocol]::ftp" to enumeration value [WinSCP.Protocol]::Ftp. But it will convert simple "ftp".

Reply with quote

adamb-
Joined:
Posts:
1
Location:
UK

Re: Error with powershell and xml settings file for WINSCP Protocol setting

Hi Martin, how simple, that worked thank you! Now to get it working with sftp.

Reply with quote

Guest

Re: Error with powershell and xml settings file for WINSCP Protocol setting

But now I have the same problem with the TlsHostCertificateFingerprint, this time even when I hardcode the string PowerShell rejects it with the same error message:
Error: The value supplied is not valid, or the property is read-only. Change the value, and then try again.
Any help very gratefully received
Adam

Reply with quote

Guest

Re: Error with powershell and xml settings file for WINSCP Protocol setting

All fixed now. I was using TlsHostCertificateFingerprint instead of SshHostKeyFingerprint in the session options.
All fixed – Thanks for reading.

Adam

Reply with quote

Advertisement

You can post new topics in this forum