WinSCP not accepting PowerShell variable
Been trying to use winscp in PowerShell, it works with the source file directly in the
This is what I am using to start
Anyone seen this type of behaviour before?
PutFiles
function. But when I switch to a variable in PutFiles
it says it succeeds, but not files end up on the server.
This is what I am using to start
try { # Load WinSCP .NET assembly Add-Type -Path "D:\Cognos_control_m_scripts\GINZ\scripts\WinSCPnet.dll" # Setup session options $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::Sftp HostName = "xxxx" UserName = "xxxx" Password = "xxxx" SshHostKeyFingerprint = "xxxx" } $session = New-Object WinSCP.Session $session.DebugLogLevel = 2 $session.DebugLogPath = "D:\WinSCPDebugNewTest.xml" try { # Connect $session.Open($sessionOptions) # Upload files $transferOptions = New-Object WinSCP.TransferOptions $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary $ftp_file = "D:\testlog.txt" $transferResult = $session.PutFiles($ftp_file, "/ftpserver/inbox/zzzzfilexzz.zip", $False, $transferOptions) # Throw on any error $transferResult.Check() # Print results foreach ($transfer in $transferResult.Transfers) { Write-Host "Upload of $($transfer.FileName) succeeded" } } finally { # Disconnect, clean up $session.Dispose() } exit 0 } catch { Write-Host "Error: $($_.Exception.Message)" exit 1 }