I have an application that does the following: directory listing, download file, download all.
I have an issue with getting the file names from WebRequestMethods.Ftp.ListDirectoryDetails. It seems that it is not possible to do so for every scenario.
WebRequestMethods.Ftp.ListDirectoryDetails returns a lineItem in the following manner:
"-rw-r--r-- 1 ftp ftp 39979 Aug 01 16:02 db to pc 2014-08-05 07-30-00.csv"
I am using the first character to determine if it is a file or directory. Then I split the file on space and get the file name after a fixed index amount within the split. The issue in my implementation is that if a file has multiple spaces then it would be incorrectly referenced with less spaces and the file would not be found when attempting to download it.
I am not able use the split.last() since a file name can have spaces nor WebRequestMethods.Ftp.ListDirectory since it does not allow us to distinguish between a Directory and a file without an extension. Nor a regex since a file name can have a date in it. Any assistance in finding a solution that completely covers all cases would be great.
bool isDirectory = line.Substring(0,1).Equals("d", System.StringComparison.OrdinalIgnoreCase);
string[] itemNames = line.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select((value, index) => new { value, index }).Where(i => i.index > 7).Select(i => i.value).ToArray();
string val = string.Join(" ", itemNames);