Topic "GetFiles Not Throwning Exception"

Author Message
JasonRkr
[View user's profile]

Joined: 2013-07-24
Posts: 13
Location: Sunny Southern California
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.

Code:

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
}
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
You have to call TransferOperationResult.Check.

See https://winscp.net/eng/docs/library_session#results
JasonRkr
[View user's profile]

Joined: 2013-07-24
Posts: 13
Location: Sunny Southern California
Sorry, I should have added that I also tried with .Check() and it still failed to throw an exception.

Jason
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
And I should have notices your dump of the Session.GetFiles result.
Please attach a complete session log file.
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License