Host invalidcharacter does not exist
Hello. I encountered this problem (with powershell) and this thread. In my case, the problem was an invalid character.
The hostname property is set with this regexp:
Problem: the regexp output includes the carriage return character (in powershell: "`r").
Note that the powershell error does not show the carriage return character anywhere. I found it by looking at the session output. $session.Output:
Look at the hostname, it ends with "%0D". That is not good...
The fix? Replace the invalid character with nothing:
Error: Exception calling "Open" with "1" argument(s): "Host "<FQDN>" does not exist."
The hostname property is set with this regexp:
$sftpLine -match '(^sftp -o Port=)(?<port>[0-9]+) (?<username>.*)\@(?<hostname>.*)$'
$sftpHostname=$matches.hostname
Problem: the regexp output includes the carriage return character (in powershell: "`r").
$sftpHostname.Replace("`r",'') -eq $sftpHostname
False
Note that the powershell error does not show the carriage return character anywhere. I found it by looking at the session output. $session.Output:
...
winscp> open "sftp://username:***@hostname%0D:2222" -hostkey="ssh-rsa 2048 xx:xx:xx.." -timeout=15
...
Look at the hostname, it ends with "%0D". That is not good...
The fix? Replace the invalid character with nothing:
$sftpHostname=$matches.hostname.Replace("`r",'')