Issues with Synchronisation & FileMask

Advertisement

Optimaximal
Joined:
Posts:
3
Location:
United Kingdom

Issues with Synchronisation & FileMask

As part of a SQL Server SSIS package, I'm attempting to download files from an FTPS source using a combination of Powershell and the WinSCP .NET Assembly.

I've used it elsewhere just fine, but I'm having issues making the file mask work correctly with Synchronisation.

The files on the FTP are of a format AA_Unsubscribes_Timestamp.txt, where AA is a collection of letters that could be anything, defined earlier in the SSIS package.

I have the following on a try catch loop in the powershell script:

$session = New-Object WinSCP.Session

# Connect to Remote Server, download files and remove
try
{
   # Connect
   $session.Open($sessionOptions)

   # Set up transfer options
   $transferOptions = New-Object WinSCP.TransferOptions -Property @{
      TransferMode = [WinSCP.TransferMode]::Automatic
      FileMask = "CF_Unsubscribes_*.txt"
   }
   
   # Synchronize files to local directory, collect results
   $synchronizationResult = $session.SynchronizeDirectories(
      [WinSCP.SynchronizationMode]::Local, 
      $localPath, 
      $remotePath, 
      $False, 
      $transferOptions
   )
}
catch
{
exit 1
}
Finally
{
$session.Dispose()
}

Unless I'm misreading it, this should only pull down the files beginning with, for example, CF. As it stands, it's pulling down every file, regardless of the mask.

Am I doing something extremely dense?

Edit - The WinSCP Log File attached.
Description: WinSCP Log File

Reply with quote

Advertisement

Optimaximal

Ok, further research tells me that using asterisk will collect any files with either the former or latter item.

How do you use EscapeFileMask in the context of directory synchronisation?

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Re: Issues with Synchronisation & FileMask

TransferOptions is 7th argument of Session.SynchronizeDirectories method:
https://winscp.net/eng/docs/library_session_synchronizedirectories

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

See https://winscp.net/eng/docs/faq_library_parameters

Reply with quote

Advertisement

You can post new topics in this forum