Prooblem adding filemask to my script

Advertisement

Honky
Joined:
Posts:
6

Prooblem adding filemask to my script

Hi Winscp Guru's,

my Script works very nice but now i would like to add an filemask to transfer only files older than 5minutes.

Do you an idea how set this in my script?

param (
    $localPath = "F:\Test-Sync01\",
    $remotePath = "/Test-Sync01/"
)
 
try
{
    # Load WinSCP .NET assembly
    Add-Type -Path "F:\syncapp\WinSCPnet.dll"
 
   

    # Setup session options
    $sessionOptions = New-Object WinSCP.SessionOptions
    
  
    $sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
    $sessionOptions.HostName = "server08"
    $sessionOptions.UserName = "syncusr"
    $sessionOptions.Password  = "BLBALBLA"
    $sessionOptions.SshHostKeyFingerprint = "ssh-rsa 1024 13:d3:ef:ee:4d:cc:22:31:04:aa:1e:cd:7b:c7:42:02"
    $session = New-Object WinSCP.Session

        
 
    try
    {
        # Connect
        $session.Open($sessionOptions)

        $transferOptions = New-Object WinSCP.TransferOptions
        $transferOptions.FileMask = "*<5N"

        # Synchronize files to local directory, collect results
        $synchronizationResult = $session.SynchronizeDirectories(
            [WinSCP.SynchronizationMode]::Remote, $localPath, $remotePath, $False, transferOptions)
 
         
        # Iterate over every download
        foreach ($download in $synchronizationResult.Uploads)
        {
            echo $download.FileName
            # Success or error?
            if ($download.Error -eq $Null)
            {
                Write-Host ("Download of {0} succeeded, removing from source" -f 
                    $download.FileName)
             
                try
                {
                    Remove-Item $session.EscapeFileMask($download.FileName)
                    Write-Host ("Removing of file {0} succeeded" -f
                        $download.FileName)
                }
                catch [Exception]
                {
                    Write-Host ("Rmoving 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
}
Last edited by Honky on 2015-05-13 12:54; edited 2 times in total

Reply with quote

Advertisement

Honky
Joined:
Posts:
6

Hi prikryl,

thanks for your reply. I readed this sites before.

But my Script ignores any TransferOptions. Do you have any idea in which line the problem could be?

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,517
Location:
Prague, Czechia

You are passing the transferOptions to mirror parameter of SynchronizeDirectories and you are missing $.

It should be:

[WinSCP.SynchronizationMode]::Remote, $localPath, $remotePath, $False, $False, $transferOptions

Reply with quote

Advertisement

You can post new topics in this forum