0 votes
by (320 points)

When I try to upload a non existent file using Rebex SFTP to the server using the Upload command as follows:

request.Upload("C:\Temp\TempFile.txt", destinationFilePath,
               TraversalMode.MatchFilesShallow, TransferMethod.Copy,

where TempFile.txt doesn't exist at the source path specified. The upload method doesn't throw an exception. The BatchTransferProblemDetected event handler doesn't get invoked as well.

I am trying to test an application and if I however, let the TempFile.txt to be available on the local folder till the first response is read from the server via the Response_Read Event handler and thereafter delete the file, then the BatchtransferProblemDetected event is raised and an exception is thrown. Is there any way to capture the error when it tries to upload a non existent file itself as in my application I can't hold the file till I receive the first response from the server?

Applies to: Rebex SFTP

1 Answer

0 votes
by (70.2k points)

It is a feature of the TraversalMode.MatchFilesShallow. Imagine these two scenarios:

1) You call Upload("C:\Temp\*.txt", TraversalMode.MatchFilesShallow);
The method searches the "C:\Temp" directory for every "*.txt" file. If no such file is found, the method doesn't throw an exception, which I think is expected behavior.

2) You call Upload("C:\Temp\TempFile.txt", TraversalMode.MatchFilesShallow);
This is special case of the call above. You don't want to search for all "*.txt" files, but for the "TempFile.txt" only. The method doesn't distinguish between these two scenarios, so no exception is thrown, which can be confusing.

To get an exception when the source file doesn't exist, please use the TraversalMode.NonRecursive instead.