Topic "Filemask in place but not working"

Author Message
reemster0180
[View user's profile]

Joined: 2015-06-21
Posts: 3
I use the WinSCP (5.7.4) powershell script that will move all files in a remote folder from the SFTP server. The issue I have is partly because of the bad design of the folder structure (where I have no influence at)

I have a root folder for user 'ftp01' and that folder contains the following (sub)folders with XML files in it.

EXCLUDE FOLDERS:

/cygdrive/c/program files (x86)/icw/home/ftp01/Input/folderA/acc/
/cygdrive/c/program files (x86)/icw/home/ftp01/Input/folderA/prod/
/cygdrive/c/program files (x86)/icw/home/ftp01/Input/folderB/acc/
/cygdrive/c/program files (x86)/icw/home/ftp01/Input/folderB/prod/

ROOT (/cygdrive/c/program files (x86)/icw/home/ftp01/Input)

|
-->FolderA
| |
| -->test (I want these XML files)
| -->acc
| -->prod
|
-->FolderB
| |
| -->test (I want these XML files)
| -->acc
| -->prod

I want the script to fetch all xml files from ALL subfolders named 'test' and move them to my local directory with one script and kick it off with a windows scheduled task.

If I point the script to only one "test" folder the script works perfectly, but when I use ROOT folder as remotepath and experiment with i.e. filemasks it won't work.

I can clone the script a couple of times with a different remotepath but then I have to maintain 6 scripts and I think it can be so much better.

I use CopSSH server for windows 2008R2. I attached the script to the post.

I hope you can help me out.

Thanks in advance!

Regards,

Remy Bosma
Forum-sample.txt (3.19 KB) [Download]

Description: (none)

Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
Your code looks correct. Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.
reemster0180
[View user's profile]

Joined: 2015-06-21
Posts: 3
Thanks for your quick response. I've attached the log as requested.
SessionLog.log (25.8 KB) Private file

Description: Replaced IP and FINGERPRINT if that's not a problem.

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
You are missing mirror and criteria arguments in Session.SynchronizeDirectories call.

It should be:

$synchronizationResult = $session.SynchronizeDirectories([WinSCP.SynchronizationMode]::Local, $localPath, $remotePath, $false, $false, [WinSCP.SynchronizationCriteria]::Time, $transferOptions)

See https://winscp.net/eng/docs/library_session_synchronizedirectories
reemster0180
[View user's profile]

Joined: 2015-06-21
Posts: 3
Works like a charm my friend! Remind me to buy a beer for you when you are in the Netherlands!

Ps. is there also a way to exclude the creation of i.e. the "ACC" folder so all the XML files (from different source folders) will directly be stored in the "\Output" folder instead within WinSCP? Otherwise I will implement a separate piece of code that will take care of that part.

Anyway.... Many many thanks!
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
No you cannot have WinSCP flatten the directory structure, if that's what you ask for.
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License