Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: WinSCP not accepting PowerShell variable

Please post session log files (Session.SessionLogPath) from both scenarios.
lmccourt

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?