Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

tkennedy

Re: Download multiple files from an array

I re-wrote the function and was able to get it to work. Thanks Martin!
tkennedy

Re: Download multiple files from an array

After digging further it looks like the problem is further down in my code. I am trying to do a file rename using the wildcard name which is giving an error. The error drops to a catch/finally block and exits the script.
if ($RenameOnServer -eq $true) {
     # If the file was downloaded successfully rename it but leave it on the server
     $Session.MoveFile($FullDLFile, "$FullDLFile$RenameExtension")                       
}

Since I'm using a wildcard, I do not know the exact name of the file. Is there a way to grab the file name of the file I just downloaded?
tkennedy

Re: Download multiple files from an array

Attached is a session log. If both files exist on the server, then they are both downloaded. If the Weekly_Values file exists only (the first in the array), it is downloaded if only the Monthly_Values file exists, nothing is downloaded.
martin

Re: Download multiple files from an array

I do not see a reason why this should not work.
Please set Session.DebugLogPath and attach the log.
tkennedy

Download multiple files from an array

I'm using powershell to script the download of multiple files. The file names are held in an array and I use a foreach loop to loop through the array. This works great as long as each file in the array is on the server, but if one of the files is not available, none of the successive files in the array are downloaded. I read https://winscp.net/eng/docs/scriptcommand_get#net and it states that I need to call GetFiles for each file I'm trying to download. Can you please help me with my logic on this? Here is my code:
$GetFileMask = @("Weekly_Values*.pgp", "Monthly_Values*.pgp")
 
# Download the files according to the file mask
foreach ($file in $GetFileMask) {
 
         # Download the file and throw on any error
         $transferResult = $Session.GetFiles("$ServerPath$file", "$DLPATH$file")
         $transferResult.Check();
}

Any help on this would be greatly appreciated. This is driving me nuts.