Topic "Get operation doesn't throw error when file is not found on server"

Author Message
sumangeorge
[View user's profile]

Joined: 2016-12-15
Posts: 15
Location: Detroit
I was doing some testing of my code.
It seems one of my Get operation (Which copies file from server to my local) is passed even if there is no file present in the server.
In the code below there is no error in this scenario.

Code:
Set transferResult = session.GetFiles("/read1.me", strTemp_File_Dir, False, transferOptions)
    If Err.Number <> 0 Then
        ' Disconnect, clean up
        MsgBox ("Got Error!!")
        session.dispose
    End If
    Err.Clear
    ' Restore default error handling
    On Error GoTo 0
sumangeorge
[View user's profile]

Joined: 2016-12-15
Posts: 15
Location: Detroit
Ok so i got a workaround for this issue.
For those facing the same issue please see my response below:
We can check if the file exists before hitting Get request.
In my case i need to throw error and send mails to user saying that file doesn't exist.:
Code:
    fileExist = session.FileExists("/read.me.txt")
    If (fileExist = True) Then
        Set transferResult = session.GetFiles("/read1.me", strTemp_File_Dir, False, transferOptions)
    End If
martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26711
Location: Prague, Czechia
That's by design. The argument of the GetFiles method is a file mask. In your case that mask can actually match a single specific file only. Still, if the mask does not match anything, it's not an error. You can use the return value of the method to check if anything was downloaded (instead of explicitly checking file existence - what is prone to race conditions).
Advertisements

You can post new topics in this forum

Search

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