How can I change this WinSCP script to only to download .csv files and no other files?

148 Views Asked by At

I would like to change this PowerShell WinSCP script which is connecting to an SFTP Server, to only download .csv files.

What part of the following portion of the script would I need to change?

# Connect
$session.Open($sessionOptions)

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

There are 1 best solutions below

0
Martin Prikryl On BEST ANSWER

Specify a filemask using TranferOptions.FileMask to restrict the synchronization to specific extensions.

$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.FileMask = "*.csv"

$synchronizationResult = $session.SynchronizeDirectories(
    [WinSCP.SynchronizationMode]::Local, $localPath, $remotePath, $False, $False,
    [WinSCP.SynchronizationCriteria]::Time, $transferOptions)