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

martin

Re: Synchronize file type in order - help needed

Use include file mask *.xml for the first step and exclude file mask |.xml for the second step.
See https://winscp.net/eng/docs/file_mask
malva

Synchronize file type in order - help needed

Hi!

I'm synchronizing directories and all works fine but I need help.
I would like to download (synchronize) first all files that are NOT .xml and then download remaining .xml files.
Anybody could help me. Please.

m.


    Try

    {
        # Connect
        $session.Open($sessionOptions)

        $localPath = "E:\test\import"
        $remotePath = "/"

        # Synchronize files to local directory, collect results
        $synchronizationResult = $session.SynchronizeDirectories(
            [WinSCP.SynchronizationMode]::Local, $localPath, $remotePath, $False, $False, [WinSCP.SynchronizationCriteria]::Time, $transferOptions)


        foreach ($download in $synchronizationResult.Downloads)
        {
            # Success or error?
            if ($download.Error -eq $Null)
            {
                Write-Host ("Download of {0} succeeded, removing from source" -f
                    $download.FileName)
                # Download succeeded, remove file from source
                $removalResult = $session.RemoveFiles($session.EscapeFileMask($download.FileName))
 
                if ($removalResult.IsSuccess)
                {
                    Write-Host ("Removing of file {0} succeeded" -f
                        $download.FileName)
                }
                else
                {
                    Write-Host ("Removing of file {0} failed" -f
                        $download.FileName)
                }
            }
            else
            {
                Write-Host ("Download of {0} failed: {1}" -f
                    $download.FileName, $download.Error.Message)
            }
        }
    }
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
    }
 
    exit 0
}
catch [Exception]
{
    Write-Host $_.Exception.Message
    exit 1
}