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

Advertisement

sumangeorge
Joined:
Posts:
15
Location:
Detroit

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

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.

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

Reply with quote

Advertisement

sumangeorge
Joined:
Posts:
15
Location:
Detroit

Re: Get operation doesn't throw error when file is not found on server

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.:
    fileExist = session.FileExists("/read.me.txt")
    If (fileExist = True) Then
        Set transferResult = session.GetFiles("/read1.me", strTemp_File_Dir, False, transferOptions)
    End If

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
40,567
Location:
Prague, Czechia

Re: Get operation doesn't throw error when file is not found on server

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).

Reply with quote

Advertisement

You can post new topics in this forum