WinSCP not accepting PowerShell variable

Advertisement

lmccourt
Guest

WinSCP not accepting PowerShell variable

Been trying to use winscp in PowerShell, it works with the source file directly in the 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
}
Anyone seen this type of behaviour before?

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum