Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

floppymaster

The new version resolves the problem. Thanks.
martin

Re: Session code generator for PowerShell outputs un-escaped dollar signs in double quoted literals

This bug has been added to the tracker:
https://winscp.net/tracker/1590

I'm sending you an email with a development version of WinSCP to the address you have used to register on this forum.
martin

Re: Session code generator for PowerShell outputs un-escaped dollar signs in double quoted literals

Thanks. Will look into this.
floppymaster

Alternatively, the dollar sign may be escaped using a backtick (`) character. Backticks also need to be escaped.

pa$w"or`d -> "pa`$w`"or``d"
floppymaster

Session code generator for PowerShell outputs un-escaped dollar signs in double quoted literals

The Powershell code generator encapsulates string literals in double quotes. If any of the values contain a dollar sign, Powershell will interpret this as a variable reference.

For example:

# Set up session options

$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Sftp
    HostName = "ftp.example.com"
    UserName = "myuser"
    Password = "pa$sword" # Accidental reference to '$sword' variable
    SshHostKeyFingerprint = "ssh-rsa 2048 0b:1e:4b:29:43:7e:a3:aa:f4:6b:fe:50:cb:32:f8:35"
}


An easy solution would be to use single quotes instead.

# Set up session options

$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Sftp
    HostName = 'ftp.example.com'
    UserName = 'myuser'
    Password = 'pa$sword'
    SshHostKeyFingerprint = 'ssh-rsa 2048 0b:1e:4b:29:43:7e:a3:aa:f4:6b:fe:50:cb:32:f8:35'
}