Topic "Prooblem adding filemask to my script"

Author Message
Honky
[View user's profile]

Joined: 2015-05-08
Posts: 6
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?

Code:

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
Advertisements
Honky
[View user's profile]

Joined: 2015-05-08
Posts: 6
anybody ?!?, please. Smile
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
Use TransferOptions.FileMask
http://winscp.net/eng/docs/library_transferoptions
http://winscp.net/eng/docs/file_mask

The mask will be like: <5N
Honky
[View user's profile]

Joined: 2015-05-08
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?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
Show us your code with TransferOptions.
Honky
[View user's profile]

Joined: 2015-05-08
Posts: 6
Thanks,i added the tranferoptions in the upper script.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
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
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