Search Folders / foreach loop upload

Advertisement

JamesM
Guest

Search Folders / foreach loop upload

Hi guys

I'd like to mirror the powershell command:

foreach ($folder in $folderarray) {
Copy-Item "D:\Users\username\*\*\*\$folder\files\*" -Destination
"D:\Users\username\Desktop\temp\" -Recurse
}

in a way that instead of moving files from one local folder to another the files are moved to an SFTP (the SFTP session is working fine and uploading files is not a problem in general.)

This is what I'd attempted to do:

foreach ($folder in $folderarray) {
$session.PutFiles("D:\Users\username\*\*\*\$folder\files\*", "/NewRelease/$folder/", $False, $transferOptions)

But this set up doesn't work in the same way, could someone please tell me I can set this up correctly?

Thanks

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
28,802
Location:
Prague, Czechia

Re: Search Folders / foreach loop upload

WinSCP does not support file masks like this.

You have to list subfolders in respective parent folders and loop over them (three nested loops).

Another option is using Session.EnumerateRemoteFiles:
https://winscp.net/eng/docs/library_session_enumerateremotefiles
But that's probably not the best solution in your case (with fixed $folder\files).

Reply with quote

JamesM
Guest

Hi Martin

Thanks for your response. Good to know that WinSCP doesn't support file masks in that way.

What I did was create an array of the different folder names and put the initial ForEach loop inside another of this array, it seemed to do the trick!

Cheers

Reply with quote

Advertisement

You can post new topics in this forum