powershellftpsftpwinscpwinscp-net

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


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)

Solution

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