Winscp system error. code: 123. the filename, directory name, or volume label syntax is incorrect

Issue Description

Hello,

I found an interesting bug in the WinSCP module when using PSDrives. I'm trying to send a file from a PSDrive to a remote server with Send-WinSCPItem. The PSDrive is a shortcut to a remote SMB drive. When I'm using a regular UNC path the module is fine.

Example

# Example PS Drive $exportPath = New-PSDrive -Name "WinScpTestDrive" -PSProvider FileSystem -Root "\\fileserver1.example.com" # Remote Destination $sftp_destination_directory = '/test/' # Remote Credentials $credentials_sftp_session = Import-Clixml -Path "$($PSScriptRoot)\cred.cred" $sftp_session_arguments = @{ HostName = 'server.example.com' SshPrivateKeyPath = "$($PSScriptRoot)\key" SshHostKeyFingerprint = 'ssh-rsa 2048 59:a5:ae:11:d3:9f:ec:95:c5:17:5b:b8:f5:50:f4:d9' Credential = $credentials_sftp_session } $sftp_session = New-WinSCPSession @sftp_session_arguments $sftp_send_parameters = @{ WinSCPSession = $sftp_session # Working -> Resolves the actual UNC Path, not the PSDrive Path Path = (Convert-Path $exportPath) <# Not working -> Uses the PSDrive path, which seems unavailable to the cmdlet. Path = $exportPath #> Destination = $sftp_destination_directory } # Send the Item $sftp_send_output = Send-WinSCPItem @sftp_send_parameters if ($sftp_send_output.IsSuccess -eq $true) { Write-Output "File $($exportParams.Path) exported successfully!" } else { Write-Error 'File not sent!' }

Expected Output

File1 exported successfully!

Some more Powershell Output

$exportPath WinScpTestDrive:\File1.txt # Result of Path Test PS D:\iPhone4All\Abrechnungsskript> Test-Path $exportPath True #Result of Get-PSDrive Get-PSDrive WinScpTestDrive | FL Name : WinScpTestDrive Description : Provider : Microsoft.PowerShell.Core\FileSystem Root : \\fileserver1.example.com\SMB_Share CurrentLocation :

Actual Output

PS C:\Temp\SCP.ps1> C:\Temp\SCP.ps1 Send-WinSCPItem : WinSCP.SessionRemoteException: File or folder 'WinScpTestDrive:\File1.txt' does not exist. System Error. Code: 123. The filename, directory name, or volume label syntax is incorrect At C:\Temp\SCP.ps1:34 char:33 + $sftp_send_output = Send-WinSCPItem @sftp_send_parameters + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Send-WinSCPItem

WinSCP-PowerShell Version

Get-Module WinSCP ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Script 0.0.0.0 WinSCP {ConvertTo-WinSCPEscapedString, Get-WinSCPChildItem, Get-WinSCPItem, Get-WinSCPItemChecksum...}

No idea why it's not showing the right version This is the right version number from the Module data... I downloaded the module in mid of June.

Environment

Name : Windows PowerShell ISE Host Version : 5.1.14409.1005 InstanceId : 59623792-ebca-4e81-8cd0-afed56baeec1 UI : System.Management.Automation.Internal.Host.InternalHostUserInterface CurrentCulture : en-US CurrentUICulture : en-US PrivateData : Microsoft.PowerShell.Host.ISE.ISEOptions DebuggerEnabled : True IsRunspacePushed : False Runspace : System.Management.Automation.Runspaces.LocalRunspace

Also:

  • Windows Server 2012 R2 x64
  • Got Windows Updates ~2 weeks ago