Re: WinSCP not accepting PowerShell variable
Please post session log files (
Session.SessionLogPath) from both scenarios.
Before posting, please read how to report bug or request support effectively.
Bug reports without an attached log file are usually useless.
Session.SessionLogPath) from both scenarios.
PutFiles function. But when I switch to a variable in PutFiles it says it succeeds, but not files end up on the server.
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
}