lines
is a string array, not the FTP output. It should contain 1 element per file on the FTP server. Personally I wouldn't use ReadToEnd
but rather enumerate line by line.
$reader = New-Object System.IO.StreamReader -ArgumentList $ftprequest.GetResponse().GetResponseStream()
while -not $reader.EndOfStream {
$line = $reader.ReadLine()
//Break up the line of data
}
You now need to break up each line to get the details of that line. I don't know what your FTP output looks like so you'll need to look at the output and figure out the actual parsing. I would daresay it is probably a series of fields separated by whitespace so for each line split on the whitespace again although it likely won't work for all cases. Here's a link to one possible approach. It is going to depend upon the output of your FTP server though. Ultimately you just end up breaking up the line into its fields and then storing that into a normalized structure you can then later use to do the comparison with the local files.
Looking at your example output you might be able to parse a line using just Split
but limited to 4 entries: date, time, size and filename. By limiting to 4 the filename (with or without spaces) will be the final entry. If the size is <DIR>
then it is a directory.