Sync down specified folder (under subdirs)

Advertisement

Andieboy
Joined:
Posts:
2

Sync down specified folder (under subdirs)

Dear All,

I'm new on this forum, altought I'm using winSCP for years. But now, I've faced a problem, I can't solve for days.
I have the following directory structure on a SFTP server:

/reportfiles/XYreports/yyyymmdd/termid_datetimestamp/

Which means, that under XYreports (last fix dirname), there are date-named directories, whereunder there are hundreds of terminalID driven dirnames. All those terminalID subdirectories contains only 1 ZIP file, whise are important for us. But only for specified terminalIDs!

So for exact example:

/reportfiles/XYreports/20171013/AAA123_20171013_091400/
/reportfiles/XYreports/20171013/AAA124_20171013_091500/
/reportfiles/XYreports/20171013/AAA125_20171013_091600/
/reportfiles/XYreports/20171013/AAA126_20171013_091700/
/reportfiles/XYreports/20171013/BBB567_20171013_091800/
...
/reportfiles/XYreports/20171014/AAA123_20171014_072400/
/reportfiles/XYreports/20171014/AAA124_20171014_072400/
...
/reportfiles/XYreports/20171015/AAA123_20171015_102200/
...

and so on. there are only 1 zip under those final subdirectories.

I'm interested on EVERY DAY, only on AAA123 -named terminal's zip file. (and later the BBB556 for example). All others I don't want even download.

My best effort was:

cd /reportfiles/XYreports/20171015/
synchronize -filemask="*AAA123*/" local  ..\transfer\

This one downloads only the AAA123 dir, with the zip inside it. But it works only in 20171015 subdirectory.
I don't want to specify the day, so I want something like

cd /reportfiles/XYreports/
synchronize -filemask="*/*AAA123*/" local  ..\transfer\

But it doesn't work, since the log says: all subdirs are excluded.
How can I do that, guys?

thanks!

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
27,459
Location:
Prague, Czechia

Re: Sync down specified folder (under subdirs)

You cannot do this with simple WinSCP scripting.
But it's easy with WinSCP .NET assembly and PowerShell
https://winscp.net/eng/docs/library_powershell

You can start with this example:
https://winscp.net/eng/docs/script_download_files_to_same_folder
And modify it to get something like:

$date = (Get-Date -Format "yyyyMMdd")

$subdirInfos =
    $session.EnumerateRemoteFiles(
        "/reportfiles/XYreports/$date", "AAA123*",
        [WinSCP.EnumerationOptions]::MatchDirectories)

foreach ($subdirInfo in $subdirInfos)
{
    Write-Host "Downloading from $($subdirInfo.FullName)"
    $session.GetFiles(
        $subdirInfo.FullName + "/*.zip", "C:\transfer\*").Check()
}

Reply with quote

Andieboy
Joined:
Posts:
2

Re: Sync down specified folder (under subdirs)

Hi Martin,

thank you for the answer, I was afraid you left the forum and I won't get any answer :)

Okay, I'll try that you mentioned.
I thought, there is some wildcard parametering in path as well, something like:
> synchronize /dir1/dir2/*/getthese*/*.zip

This means, it will download all these directories:
/dir1/dir2/ abc /getthese1/alpha.zip
/dir1/dir2/ abc /getthese2/beta.zip
/dir1/dir2/ cde /getthese8/zeta.zip
/dir1/dir2/ xyz /gettheseYX/omega.zip

and so on..

That would be something logical for me, btw, what is the reason to NOT working that way? (I don't want to change WinSCP, I just want to understand :) )

Thanx again!

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
27,459
Location:
Prague, Czechia

Re: Sync down specified folder (under subdirs)

Andieboy wrote:

I thought, there is some wildcard parametering in path as well, something like:
> synchronize /dir1/dir2/*/getthese*/*.zip
You can do this, but it will recreate a remote directory structure locally. What I understand that you do not want to.

Reply with quote

Advertisement

You can post new topics in this forum