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

And I should have notices your dump of the Session.GetFiles result.
Please attach a complete session log file.
JasonRkr

Sorry, I should have added that I also tried with .Check() and it still failed to throw an exception.

Jason
JasonRkr

GetFiles Not Throwning Exception

WinSCP 5.1.7.0
windows Server 2003 R2 with SP2
Sftp
Scripting / Automating

Downloading a file from a remote directory does not throw an exception when the file does not exist.

Here's the result from the PowerShell window:

PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> C:\scripts\labQCFileDownload.ps1

Transfers Failures IsSuccess
--------- -------- ---------
{} {} True

Another user in .NET assembly / COM library (https://winscp.net/forum/viewtopic.php?t=12773) is experiencing the same issue with putFiles, but I don't know what version of WinSCP he's running.

try

{
    # Load WinSCP .NET assembly
    # Use "winscp.dll" for the releases before the latest beta version.
    [Reflection.Assembly]::LoadFrom("\\C:\scripts\WinSCP.dll") | Out-Null
 
    # Setup session options
    $sessionOptions = New-Object WinSCP.SessionOptions
    $sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
    $sessionOptions.HostName = "xxxxxxxx"
    $sessionOptions.UserName = "xxxxxxxx"
    $sessionOptions.Password = "xxxxxxxx"
    $sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 0e:2b:76:24:bf:50:e7:29:f5:01:2b:e6:59:16:ea:10"
 
    $session = New-Object WinSCP.Session
    $session.AdditionalExecutableArguments = "/xmllog='c:\temp\lab_qc_log.xml'"
    $session.DebugLogPath = "c:\temp\lab_qc_debug.log"
    $session.SessionLogPath = "c:\temp\lab_qc_session.log"
    $session.XmlLogPath = "c:\temp\lab_qc_sessionxml.xml"
    $session.ExecutablePath = "c:\scripts\winscp.exe"
   
    try
    {
        # Connect
        $session.Open($sessionOptions)
 
        $stamp = Get-Date -f "yyyyMMdd"
        $fileDay = Get-Date -Format "dd"
        $fileName = "FTP20*"
        $remotePath = "/U/softprint/$fileName"
        $localPath = "c:\lab_qc\$fileName"
         
        $session.GetFiles($remotePath, $localpath)
    }
    catch [Exception]
    {
        Write-Host $_.Exception.Message
    }     
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
    }
 
    exit 0
}
catch [Exception]
{
    Write-Host $_.Exception.Message
    exit 1
}