Topic "Sync down specified folder (under subdirs)"

Author Message
Andieboy
[View user's profile]

Joined: 2017-10-16
Posts: 2
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:

Code:
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

Code:
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!
Advertisements
martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 27059
Location: Prague, Czechia
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:

Code:
$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()
}
Andieboy
[View user's profile]

Joined: 2017-10-16
Posts: 2
Hi Martin,

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

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 Smile )

Thanx again!
martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 27059
Location: Prague, Czechia
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.
Advertisements

You can post new topics in this forum

Search

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