* Improve errors specificity by:
a. Avoiding unnecesary wrapping in AggregateException - Using Library.Utility.Await instead of Wait / Result
b. Using messages from InnerException during TestConnection
* Fix detection of missing base directory:
Depend on error code while trying to SetWorkingDirectory, rather than very wide try/catch and a hardcoded error string (Different FTP servers return different error strings. E.g. hardcoded here was "Directory not found." while Filezilla returns "Can't open file or directory").
* Fix indentation
Intentionally seperated from the previous commit for easier reviewing (otherwise Github text diff display is confused by the removal of the large try / catch blocks)
* Fix creation of missing base directory:
(previously CreateClient would fail since it would try to SetWorkingDirectory to the not-yet-existing directory)
* Upgrade FluentFTP to v42 in an attempt to resolve TLS session issues:
duplicati/duplicati#4831
Note v40 introduced breaking changes, specifically seperating between sync and async clients.
Using a different approach this time, single async client.
* Bump FluentFTP to latest (42.0.0 --> 46.0.2)
Without await, the using statement can dispose the Stream before the
call to PutAsync completes, resulting in an ObjectDisposedException.
This fixes#4556.
Before performing test write, reset stream Position to 0, otherwise test performs zero-byte write.
When performing test read, verify that file was written correctly.
By changing to IEnumerable, it is possible to iterate only a portion of the list, which is useful when not all entries are needed (e.g., when testing a connection).
All existing backends have been updated, and any which were able to be changed to yield return results in a straightforward way now do.
Many backends had a try/catch in the List() method. Due to the fact that yield returns can't be placed within a try/catch block, these have been refactored to either scope the try/catch to the parts that (should) be the only places throwing exceptions, so that exceptions are still caught and handled.
Note that lazy evaluation may cause some changes in behavior - exceptions that were previously thrown at the point of invokation of List() may now be thrown while it is being enumerated.
I believe this will not be problematic though, as the only well-known exception seems to be FolderMissingException, which should be thrown by Test(), but TestList() attempts to enumerate the list to force this exception.
Any places that require the legacy behavior can get it by simply converting the lazy enumerable to a List()
InvariantCulture is useful when comparing / sorting human language strings in a culturely correct way. It handles things like accented letters in a way that makes sense to humans (e.g., 'a' should be sorted next to 'á', rather than after 'z').
Ordinal looks just at the raw code points of the characters. As such, it is recommended for use in cases when comparing system strings (file paths, command line parameters, config settings, etc.). Since it doesn't need to use the culture specific sorting rules, this method can often be faster.
For more information, see https://stackoverflow.com/questions/492799/difference-between-invariantculture-and-ordinal-string-comparison (and other related questions)