Powershell Parallel Connections Script Bug with Single File Download
When using the library example for parallel transfers in Powershell, if only one file is found, the entire directory is downloaded. This is not ideal when filtering the direct based on some criteria (IE, lastmodifieddate, wildcard, etc).
Here is the script: https://winscp.net/eng/docs/library_example_parallel_transfers
The issue is at line 54, this results in an empty variable within the loop when only one item exists:
I implemented a fix in my code by converting $files into an array after the list is generated further up in the code (line 31):
There is probably a more elegant way of handling this. It's only a bug if you are filtering the file list in a directory. Otherwise only one file exists in the directory, so the result is one file being download (via the whole directory).
Here is the script: https://winscp.net/eng/docs/library_example_parallel_transfers
The issue is at line 54, this results in an empty variable within the loop when only one item exists:
$fileList = $files[$start..$i] -join ";"
I implemented a fix in my code by converting $files into an array after the list is generated further up in the code (line 31):
# If single file add to array if ($files.Count -eq 1){ $files = @($files) }
There is probably a more elegant way of handling this. It's only a bug if you are filtering the file list in a directory. Otherwise only one file exists in the directory, so the result is one file being download (via the whole directory).